更改在 gradle 脚本中创建的应用程序的版本代码
Change versionCode of an App created in a gradle script
在我没有开发但必须编辑的 Android 应用程序中,我找到了这个 gradle 脚本:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.ajoberstar:grgit:1.5.0'
}
}
import org.ajoberstar.grgit.Grgit
ext {
git = Grgit.open(currentDir: projectDir)
gitVersionName = git.describe()
gitVersionCode = git.tag.list().size()
gitVersionCodeTime = git.head().time
}
task printVersion() {
println("Version Name: $gitVersionName")
println("Version Code: $gitVersionCode")
println("Version Code Time: $gitVersionCodeTime")
}
"gitVersionCode"变量在build.gradle文件中用作应用程序的"versionCode"。
这是 build.gradle 文件:
// gradle script
apply from: "$project.rootDir/tools/script-git-version.gradle"
//...
defaultConfig {
applicationId "..."
minSdkVersion 17
targetSdkVersion 25
versionCode gitVersionCode
versionName gitVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
当我生成签名 APK 并尝试添加到 beta 版本时,我收到 google 错误 "Version code already exists",但我不知道如何编辑应用程序的版本代码。
我的问题是:
- 这段代码究竟做了什么?
- 如何修改应用的版本号?
Git是一个版本控制系统。您的项目似乎存储在 Git 存储库中。
Grgit 是与 Git 一起使用的 Groovy 库。您的 Gradle 脚本正在加载此库。
git
是 Grgit
的实例。 git.tag.list()
returns a list of the Git tags used in this repository。 git.tag.list().size()
returns 该列表中的标签数。
因此,此 Gradle 脚本将 versionCode
设置为项目 Git 存储库中使用的 Git 标签的数量。
how to edit the version code of the app?
或者:
创建另一个 Git 标签,例如通过标记您尝试发布的版本,或者
更改 versionCode gitVersionCode
以停止使用 gitVersionCode
并使用其他一些编号系统
似乎是在使用this library查询git,以生成版本名称和版本代码。就版本代码而言,它似乎是根据它找到的 git 标签的数量来设置的。因此,要修改版本代码,请在您的发布提交上执行 git tag
。
如果不合适,您可以手动完成并替换
versionCode gitVersionCode
和
versionCode 99
用您的版本代码替换“99”。
在我没有开发但必须编辑的 Android 应用程序中,我找到了这个 gradle 脚本:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.ajoberstar:grgit:1.5.0'
}
}
import org.ajoberstar.grgit.Grgit
ext {
git = Grgit.open(currentDir: projectDir)
gitVersionName = git.describe()
gitVersionCode = git.tag.list().size()
gitVersionCodeTime = git.head().time
}
task printVersion() {
println("Version Name: $gitVersionName")
println("Version Code: $gitVersionCode")
println("Version Code Time: $gitVersionCodeTime")
}
"gitVersionCode"变量在build.gradle文件中用作应用程序的"versionCode"。
这是 build.gradle 文件:
// gradle script
apply from: "$project.rootDir/tools/script-git-version.gradle"
//...
defaultConfig {
applicationId "..."
minSdkVersion 17
targetSdkVersion 25
versionCode gitVersionCode
versionName gitVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
当我生成签名 APK 并尝试添加到 beta 版本时,我收到 google 错误 "Version code already exists",但我不知道如何编辑应用程序的版本代码。
我的问题是:
- 这段代码究竟做了什么?
- 如何修改应用的版本号?
Git是一个版本控制系统。您的项目似乎存储在 Git 存储库中。
Grgit 是与 Git 一起使用的 Groovy 库。您的 Gradle 脚本正在加载此库。
git
是 Grgit
的实例。 git.tag.list()
returns a list of the Git tags used in this repository。 git.tag.list().size()
returns 该列表中的标签数。
因此,此 Gradle 脚本将 versionCode
设置为项目 Git 存储库中使用的 Git 标签的数量。
how to edit the version code of the app?
或者:
创建另一个 Git 标签,例如通过标记您尝试发布的版本,或者
更改
versionCode gitVersionCode
以停止使用gitVersionCode
并使用其他一些编号系统
似乎是在使用this library查询git,以生成版本名称和版本代码。就版本代码而言,它似乎是根据它找到的 git 标签的数量来设置的。因此,要修改版本代码,请在您的发布提交上执行 git tag
。
如果不合适,您可以手动完成并替换
versionCode gitVersionCode
和
versionCode 99
用您的版本代码替换“99”。