如何在每次获取发布包时自动增加 android 构建 gradle 文件中的版本号
最佳答案
You can add Version details in the version.properties file. But, I recommended you can update the version code and version number manual because each time you build it increased by one. One more thing with that if you want to release a major update then you also need to update manually. In conclusion, the manually update version provides more controls on your updates.
compileSdkVersion 25
buildToolsVersion "25.0.2"
def versionPropsFile = file('version.properties')
if (versionPropsFile.canRead()) {
def Properties versionProps = new Properties()
versionProps.load(new FileInputStream(versionPropsFile))
def name = versionProps['VERSION_NAME']
def code = versionProps['VERSION_CODE'].toInteger() + 1
versionProps['VERSION_CODE']=code.toString()
versionProps.store(versionPropsFile.newWriter(), null)
defaultConfig {
applicationId "com.bsupits.example.autoincrement"
versionName name
versionCode code
minSdkVersion 15
targetSdkVersion 25
}
}
else {
throw new GradleException("Could not read version.properties!")
}
关于Android构建gradle文件版本号自动递增,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73715317/