Exclude assets for release build type

前端 未结 5 1018
自闭症患者
自闭症患者 2020-12-08 21:36

I\'m importing an android library in an application built with gradle, like that:

dependencies {
    compile \'com.e         


        
5条回答
  •  情书的邮戳
    2020-12-08 22:10

    I ended up doing the following:

    android.applicationVariants.all { variant ->
    
      if (variant.name.contains('Release')) {
        // exclude source and sourcemap from release builds
        def noJsSourceTask = task("delete${variant.name}JsSource", type: Delete) {
          delete "${buildDir}/intermediates/assets/${variant.dirName}/js"
          delete "${buildDir}/intermediates/assets/${variant.dirName}/great.min.js.map"
        }
        variant.mergeAssets.finalizedBy noCeJsSourceTask
      }
    }
    

    It works ok, but there are a few things I don't really like:

    • I'm touching at the files produced by a task after it is done (the finalizedBy), so it doesn't work well with "up-to-date" checking. But it's only for release builds, I'm doing debug ones more often
    • the path of the files to delete is manually built. I'm not sure if it's generic enough to be reused in other projects as-is
    • I'm selecting the variants based on their name. I would have liked something more structured.

提交回复
热议问题