androidjenkinsgradledexguard

How to set up dexguard for jenkins builds on app with multiple flavors?


I have an app with multiple flavors where I'm using dexguard, and I've decided to set it up on Jenkins. Dexguard licenses are located in /app/flavor/ for eash license, but Jenkins always takes the license from the last flavor. The build fails with the error code:

The package name from the AndroidManifest.xml file [com.example.android.flavor1.something] doesn't match the package name [com.example.android.flavor6.something,com.example.android.flavor6.test,com.example.android.flavor6.something.prod,com.example.android.flavor6.test] from your DexGuard license [C:\Users\CurrentUser\AndroidStudioProjects\MyApp\flavor6\dexguard-license.txt]

I have tried renaming dexguard.license to dexguard-licenseX.txt (where X is the number of flavor) and setting in flavors build.gradle to look for that name, that couldn't even find the license file. I have also tried setting up the licence location in gradle.properties with systemProp.dexguard.licence=./flavor1.

I'm currently using

release {
     System.properties['dexguard.license'] = buildscript.sourceFile.parent
     proguardFiles getDefaultDexGuardFile('dexguard-release.pro'), 'dexguard-rules.pro', 'proguard-rules.pro'
}

And that works only if I try to build the last flavor, otherwise I have to copy dexguard-license to home folder (which isn't a problem locally, but it is a problem on Jenkins).

Is there a way to set up dexguard on jenkins ?


Solution

  • Solved it: Added this code to build.gradle of every module:

    def getCurrentModule() {
    Gradle gradle = getGradle()
    String  tskReqStr = gradle.getStartParameter().getTaskRequests().toString()
    
    if(tskReqStr.indexOf( ":currentModule:" ) >= 0 )
        return ":currentModule:"
    else
      {
        println "NO MATCH FOUND"
        return ""
      }
    }
    

    and this in buildTypes-release:

    if (getCurrentModule() == ":currentModule:") {
                System.properties['dexguard.license'] = buildscript.sourceFile.parent
            }
            proguardFiles getDefaultDexGuardFile('dexguard-release.pro'), 'dexguard-rules.pro', 'proguard-rules.pro'