Search code examples
androidgradlebuild.gradlegradlew

Gradle: initwith don't work for minify and proGuard


In my code I have 5 build types. In my case, the QA one should initWith release, but this is not working, since when I run ./gradlew assembleQa is not generating the mapping.txt

What I have try to far:

qa.initWith(buildTypes.release)
qa { 
    ... 
}
qa { 
    initwith release
    ... 
}
qa { 
    initwith buildTypes.release
    ... 
}

In all cases it won't get the property from release (since is not building the mapping)

    minifyEnabled true
    proguardFiles 'proguard-android.txt', 'proguard-rules.pro', 'proguard-log.pro'

So now I have this:

qa {
    ...
    minifyEnabled true
    proguardFiles 'proguard-android.txt', 'proguard-rules.pro', 'proguard-log.pro'
    ...
}

release {
    ...
    minifyEnabled true
    proguardFiles 'proguard-android.txt', 'proguard-rules.pro', 'proguard-log.pro'
    ...
}

What is not vert nice. How can I make initWith works? Thanks


Solution

  • Besides what I found in some Gradle courses, look like the order matter (at least inside the same function}

    So, inside buildTypes to make initWith work it would need to come after. like this:

    release {
        ...
        minifyEnabled true
        proguardFiles 'proguard-android.txt', 'proguard-rules.pro', 'proguard-log.pro'
        ...
    }
    
    qa {
        ...
        initWith buildTypes.release
        ...
    }