I'd like to apply different VersionCode to make apk file.
For debug only fix it to 1
, and for release whatever number specified in defaultConfig.
Below code gives mypackage-release-1.apk
file as assembleRelease artifact, which is not expected. I expected mypackage-release-10111.apk
for that.
why the line debug { defaultConfig.versionCode=1 }
affects assembleRelease artifact?
defaultConfig {
versionCode 10111
versionName '2.5.4'
minSdkVersion 10
targetSdkVersion 21
}
signingConfigs {
debug {
project.ext.loadSign = false
defaultConfig.versionCode = 1 // Why this value applied to assembleRelease?
}
release {
project.ext.loadSign = true
applicationVariants.all { variant ->
variant.outputs.each { output ->
def file = output.outputFile
output.outputFile = new File(file.parent, file.name.replace(".apk", "-" + defaultConfig.versionCode + ".apk"))
}
}
}
}
buildTypes {
debug {
signingConfig signingConfigs.debug
}
release {
signingConfig signingConfigs.release
}
}
Late on the party...
The entire gradle file evaluated before any task execution, so you are basically changing the default versionCode
while declaring debug
configs. There is no direct way to reset versionCode
from buildType
, but the link on the other answer do the trick by declaring a task on build variants.
android {
...
defaultConfig {
...
}
buildTypes {
...
}
applicationVariants.all { variant ->
def flavor = variant.mergedFlavor
def versionCode = flavor.versionCode
if (variant.buildType.isDebuggable()) {
versionCode += 1
}
flavor.versionCode = versionCode
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With