Gradle upgrade 4.1 doesn't load versionCode an

2019-07-27 04:42发布

问题:

I upgraded my gradle to 4.1

project.ext.set("currentGradleVersion", "4.1")

 dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0'
    }

I moved all the "compile" to "implementation" since "compile" is deprecated. Also changed variant.outputs.each to variants.outputs.all

The apk generates with the correct versionName

But when I used aapt command "./aapt d badging **.apk" All the below are returned as empty, what went wrong?

versionCode='' versionName='' platformBuildVersionName=''

回答1:

After some ... long.. researches :

Here are some solutions to update the versionCode and versionName:

Gradle 3.0.0 alpha variant output issue

Gradle plugin 3.0 rewrite versionName


In a Brief : It is something no more supported by the latest gradle version. To fix it, you can ADD this piece of code in your current code :

applicationVariants.all { variant ->
    ...
        variant.outputs.all { output ->
            ...
            output.setVersionCodeOverride(VERSION_CODE_INTEGER)
            output.setVersionNameOverride(VERSION_NAME_STRING)
            ...
        }
    ...
    }
}