如何更新本地应用程序的版本号

我在 Android 中使用了本地的 React。如何更新应用程序中的版本号?当我得到这个错误。

我正在按照这个 URL 生成文件 Https://facebook.github.io/react-native/docs/signed-apk-android.html

我试过修改 AndroidManifest.xml 文件,但是在我构建它之后,该文件会被自动修改回来。

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.facebook.react"
android:versionCode="1"
android:versionName="1.0" >

这里,我修改了 XML:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.facebook.react"
android:versionCode="2"
android:versionName="1.1" >

之后,生成文件会自动变回。

enter image description here

127654 次浏览

你应该在 android/app/build.gradle中改变你的 versionCodeversionName:

android {


defaultConfig {


versionCode 1
versionName "1.0"
        

{...}
}


{...}
}

请注意,versionCode必须是一个大于以前版本所使用的整数,而 versionName是人类可读的版本,可能会显示给用户。

@ Joseph Roque 是正确的,您需要更新 android/app/build.gradle中的版本号。

下面是我如何自动化这个过程,并将其绑定到 package.json中的包版本中,然后 git 提交。

android/app/build.gradle:

/* Near the top */


import groovy.json.JsonSlurper


def getNpmVersion() {
def inputFile = new File("../package.json")
def packageJson = new JsonSlurper().parseText(inputFile.text)
return packageJson["version"]
}
/* calculated from git commits to give sequential integers */
def getGitVersion() {
def process = "git rev-list master --first-parent --count".execute()
return process.text.toInteger()
}




......




def userVer = getNpmVersion()
def googleVer = getGitVersion()


android {
...
defaultConfig {
.....
versionCode googleVer
versionName userVer


ndk {
abiFilters "armeabi-v7a", "x86"
}
}

备注:

  • 重要的是,versionCode是一个整数-所以我们不能在这里使用语义版本控制。这是用在游戏商店告诉哪个版本后,其他版本-这就是为什么它绑定到 git 提交在 getGitVersion

  • 然而,versionName显示给用户-我在这里使用语义版本控制,并在我的 package.json中存储实际值。感谢 https://medium.com/@andr3wjack/versioning-react-native-apps-407469707661

对于那些希望自动化这一点,并有 iOS 的同时,您可以使用 反应-本地-版本来设置版本号。

您所需要做的就是更新 package.json 文件中的 版本编号,然后运行以下命令:

$ npx react-native-version --never-amend


[RNV] Versioning Android...
[RNV] Android updated
[RNV] Versioning iOS...
[RNV] iOS updated
[RNV] Done
✨  Done in 0.39s.

我希望这能帮助别人。

在 app.json 中将 versionCode设置为 android:

{
"expo": {
"name": "App Name",
...
"android": {
"package": "com.app.name",
"permissions": [],
"versionCode": 2
}
}
}

档号: https://docs.expo.io/versions/latest/workflow/configuration/#versioncodeversion-number-required-by-google-play-increment-by-one-for-each-release-must-be-an-integer-httpsdeveloperandroidcomstudiopublishversioninghtml

如果有人面对

错误的版本代码如 -31284

然后确保在 android/app/build.gradle中不使用 Molecular ateBuildPerCPUArchitecture

def enableSeparateBuildPerCPUArchitecture = false

还有

更新 android/app/build.gradle的版本代码和更改名称:

android {


defaultConfig {


versionCode 1
versionName "1.0"


{...}
}


{...}
}

我也有同样的问题,我检查了以上所有的答案,我犯了一个愚蠢的错误,因为没有工作,为我。万一你们犯了和我一样的错误,试试这个。

  1. 版本可以是十进制数,如1.0或1.0.1等
  2. 但是 VersionCode 不能是十进制数应该是1,2,3等等,而不是1.1或者2.2

在 project/app/build.gradle 中

android {
defaultConfig {
versionCode 1 // do not use decimal number here
versionName "1.0" // you can use decimal number here.
{...}
}
{...}
}

如果您正在使用 博览会并且遇到这个问题,请转到 app.json并将 版本更改为一个更高的数字。

{
"expo": {
"name": "nameofapp", // btw dont copy this
"slug": "appslug",   // btw dont copy this
"version": "1.0.0",  // here is where you change the version
...
...
...
}
}

您还需要更改 package.json中的 版本

{
...
"name": "appname",  // btw dont copy this
"version": "2.0.0", // here is where you change the version
...
"android": {
"versionCode": 2,
...
}
...
}