Disable DexGuard only for certain product flavors

杀马特。学长 韩版系。学妹 提交于 2021-01-29 04:44:16

问题


I use DexGuard and have 4 product flavors (prod, qa, dev, mock) for 2 build types (release and debug) and I don't enable DexGuard for debug builds and hence I get 4 variants (dexguardProdRelease...dexguardMockRelease) however, I don't want to enable DexGuard for dev and mock flavors.

I learnt about variantFilter that Gradle provides however, I don't know how to use that command in relation to a plugin, DexGuard, in this case.


回答1:


I was able to solve like so:

//added to filter dexguard for these flavors
variantFilter { variant ->
    def names = variant.flavors*.name

    if(names.contains("mock") && variant.buildType.name == "release") {
        variant.ignore = true
    } else if (names.contains("dev") && variant.buildType.name == "release") {
        variant.ignore = true
    }
}

And now, Gradle doesn't show tasks like dexguardMockRelease or dexguardDevRelease.

I was approaching this problem incorrectly by looking at filtering out DexGuard instead I should be looking at removing certain flavors. Here are the relevant parts of my build.gradle:

apply plugin: 'dexguard'
...
android {
      buildTypes {
          release {
              proguardFile getDefaultDexGuardFile('dexguard-release-aggressive.pro')
              proguardFile 'dexguard-project.pro'
          }
          debug {
              //dontshrink, dontoptimize and dontobfuscate are turned off
          }
     }

     productFlavors {
          prod {
                ...
          }
          qa {
               ...
          }
          dev {
                ...
          }
          mock {
                 ...
          }
    }
    //added to filter dexguard for these flavors
    variantFilter { variant ->
       def names = variant.flavors*.name

       if(names.contains("mock") && variant.buildType.name == "release") {
           variant.ignore = true
       } else if (names.contains("dev") && variant.buildType.name == 
                      "release") {
           variant.ignore = true
       }
    }
}


来源:https://stackoverflow.com/questions/42986599/disable-dexguard-only-for-certain-product-flavors

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!