我在Android上使用React native。如何在应用程序中更新版本号?因为我收到了这个错误。
我按照此网址生成文件 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" >
之后,构建文件会自动更改回来。
答案 0 :(得分:113)
您应该更改versionCode
中的versionName
和android/app/build.gradle
:
android {
defaultConfig {
versionCode 1
versionName "1.0"
{...}
}
{...}
}
答案 1 :(得分:71)
@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
是一个整数很重要 - 所以我们不能在这里使用语义版本控制。这在游戏商店中用于说明哪些版本跟随其他版本 - 这就是为什么它与getGitVersion
versionName
向用户显示 - 我在这里使用语义版本控制并将真实值存储在我的package.json
中。感谢https://medium.com/@andr3wjack/versioning-react-native-apps-407469707661
答案 2 :(得分:1)
我遇到了同样的问题,我检查了以上所有答案,但我犯了一个愚蠢的错误,因此对我没有任何帮助。万一你们中的任何人犯了与我相同的错误,请尝试此操作。
所以在project / app / build.gradle
android {
defaultConfig {
versionCode 1 // do not use decimal number here
versionName "1.0" // you can use decimal number here.
{...}
}
{...}
}
答案 3 :(得分:0)
从Google搜索时,我偶然发现了这个问题,但由于我想使流程自动化,所以没有一个答案适合我。
对于那些希望自动执行此操作并同时具有iOS的用户,可以使用react-native-version设置版本号。
安装后,您只需在package.json文件中更新版本并运行脚本即可。
$ yarn postversion
$ react-native-version --never-amend
[RNV] Versioning Android...
[RNV] Android updated
[RNV] Versioning iOS...
[RNV] iOS updated
[RNV] Done
✨ Done in 0.39s.
我希望这可以帮助其他人。
答案 4 :(得分:0)
在app.json的versionCode
下设置android
:
{
"expo": {
"name": "App Name",
...
"android": {
"package": "com.app.name",
"permissions": [],
"versionCode": 2
}
}
}
答案 5 :(得分:0)
如果有人面对
版本代码错误,例如-31284
然后确保不要在android/app/build.gradle
中使用SeparateBuildPerCPUArchitecture
def enableSeparateBuildPerCPUArchitecture = false
和
更新版本代码和android/app/build.gradle
中的名称更改:
android {
defaultConfig {
versionCode 1
versionName "1.0"
{...}
}
{...}
}