在Gradle配置中添加以下代码,强制将版本号添加到应用程序 ID 中,以避免Google Play在更新应用程序时使用旧版本的缓存:
android {
defaultConfig {
...
versionCode 1
versionName "1.0"
...
}
applicationVariants.all { variant ->
variant.outputs.all { output ->
// Forces the version code to be concatenated to the output file name.
def newName = output.outputFile.name
newName = newName.replace(".apk", "-${variant.versionCode}.apk")
output.outputFile = new File(output.outputFile.parent, newName)
}
}
}