android 如何更新React Native App的版本号

uoifb46i  于 2024-01-04  发布在  Android
关注(0)|答案(9)|浏览(236)

我正在使用Android的React native。我如何在应用程序中更新版本号?因为我得到这个错误。
我正在生成文件按照这个网址https://facebook.github.io/react-native/docs/signed-apk-android.html
我试过修改AndroidManifest.xml文件,但在我构建它之后,该文件会自动修改回来。

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

字符串
在这里,我修改了XML:

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


之后,构建文件自动变回。


的数据

kh212irz

kh212irz1#

您应该在android/app/build.gradle中更改versionCodeversionName

  1. android {
  2. defaultConfig {
  3. versionCode 1
  4. versionName "1.0"
  5. {...}
  6. }
  7. {...}
  8. }

字符串
请注意,versionCode必须是一个大于先前版本的整数,而versionName是可以向用户显示的人类可读版本。

展开查看全部
w7t8yxp5

w7t8yxp52#

@Joseph Roque是正确的,您需要更新android/app/build.gradle中的版本号。
下面是我如何将其自动化并将其绑定到package.json和git commits中的包版本中。
android/app/build.gradle中:

  1. /* Near the top */
  2. import groovy.json.JsonSlurper
  3. def getNpmVersion() {
  4. def inputFile = new File("../package.json")
  5. def packageJson = new JsonSlurper().parseText(inputFile.text)
  6. return packageJson["version"]
  7. }
  8. /* calculated from git commits to give sequential integers */
  9. def getGitVersion() {
  10. def process = "git rev-list master --first-parent --count".execute()
  11. return process.text.toInteger()
  12. }
  13. ......
  14. def userVer = getNpmVersion()
  15. def googleVer = getGitVersion()
  16. android {
  17. ...
  18. defaultConfig {
  19. .....
  20. versionCode googleVer
  21. versionName userVer
  22. ndk {
  23. abiFilters "armeabi-v7a", "x86"
  24. }
  25. }

字符串
备注:

  • versionCode是一个整数,这一点很重要--所以我们不能在这里使用语义版本控制。这是在播放商店中使用的,用来区分哪些版本在其他版本之后--这就是为什么它与getGitVersion中的git提交绑定在一起
  • 但是,versionName显示给用户--我在这里使用语义版本控制,并将真实的值存储在package.json中。
展开查看全部
3zwjbxry

3zwjbxry3#

对于那些想要自动执行此操作并同时拥有iOS的用户,您可以使用react-native-version来设置版本号。
你需要做的就是在package.json文件中更新你的version号,然后运行以下命令:

  1. $ npx react-native-version --never-amend
  2. [RNV] Versioning Android...
  3. [RNV] Android updated
  4. [RNV] Versioning iOS...
  5. [RNV] iOS updated
  6. [RNV] Done
  7. Done in 0.39s.

字符串
我希望这可以帮助其他人。

twh00eeo

twh00eeo4#

我也有同样的问题,我检查了上面所有的答案,我犯了一个愚蠢的错误,因为没有什么对我有用。
1.版本可以是十进制数字,如1.0或1.0.1等
1.但是VersionCode不能是十进制数它应该是1,2,3等,而不是1.1或2.2
在project/app/build.gradle中,

  1. android {
  2. defaultConfig {
  3. versionCode 1 // do not use decimal number here
  4. versionName "1.0" // you can use decimal number here.
  5. {...}
  6. }
  7. {...}
  8. }

字符串

jvlzgdj9

jvlzgdj95#

在app.json中的android下设置versionCode

  1. {
  2. "expo": {
  3. "name": "App Name",
  4. ...
  5. "android": {
  6. "package": "com.app.name",
  7. "permissions": [],
  8. "versionCode": 2
  9. }
  10. }
  11. }

字符串
参考: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

展开查看全部
zwghvu4y

zwghvu4y6#

如果有人面临
错误的版本代码eg - 31284
然后确保不在android/app/build.gradle中使用SeparateBuildPerCPU架构
def enableSeparateBuildPerCPUArchitecture = false

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

  1. android {
  2. defaultConfig {
  3. versionCode 1
  4. versionName "1.0"
  5. {...}
  6. }
  7. {...}
  8. }

字符串

展开查看全部
hgncfbus

hgncfbus7#

@tgf拥有的东西对Android很好,但我也想要iOS。默认的Info.plistCFBundleShortVersionString设置为$(MARKETING_VERSION),这与android/build.gradle中的versionName相同,CFBundleVersion设置为$(CURRENT_PROJECT_VERSION),这与android/build.gradle中的versionCode相同。这些在ios/AppName.xcodeproj/中的project.pbxproj中定义。这里是一个可以更新xcode文件的prerelease脚本。如果您有尚未提交的修改,它将在构建号上加1,这样构建时没有任何更改就不会导致文件更改。

  1. yarn add glob --dev

个字符
使用pre脚本运行此命令。
scripts/iosUpdateVersion.js

  1. const { globSync } = require('glob');
  2. var fs = require('fs');
  3. const { execSync } = require('child_process');
  4. const APP_VERSION = require('../package.json').version;
  5. const GET_COMMIT_COUNT = 'git rev-list master --first-parent --count';
  6. let BUILD_NUMBER = 0;
  7. if (execSync('git status --porcelain').length) {
  8. console.log('increasing build number by one to include untracked changes');
  9. BUILD_NUMBER++;
  10. }
  11. const response = execSync(GET_COMMIT_COUNT).toString();
  12. BUILD_NUMBER += Number.parseInt(response.trim());
  13. // android (taken care of in build.gradle)
  14. // versionCode googleVerver // BUILD_NUMBER
  15. // versionName userVer // APP_VERSION
  16. // ios
  17. // CFBundleVersion CURRENT_PROJECT_VERSION = 1; // BUILD_NUMBER
  18. // CFBundleShortVersionString MARKETING_VERSION = 1.0; // APP_VERSION
  19. const plist = '/ios/SplitTheTank/Info.plist'
  20. const xcodeprojs = globSync('ios/*.xcodeproj');
  21. if (xcodeprojs.length === 0) {
  22. throw 'Could not find any xcodeproj folder'
  23. }
  24. const pbxproj = `${xcodeprojs[0]}/project.pbxproj`;
  25. const data = fs.readFileSync(pbxproj, 'utf8');
  26. let result = data.replace(/(CURRENT_PROJECT_VERSION = )(.*);/g, `$1${BUILD_NUMBER};`);
  27. result = result.replace(/(MARKETING_VERSION = )(.*);/g, `$1${APP_VERSION};`);
  28. fs.writeFileSync(pbxproj, result, 'utf8');

展开查看全部
ar5n3qh5

ar5n3qh58#

所有这些React都比实际情况更困难!
即使是“React Native Version“包也不能完成任务。它忘记更新一些文件,如info.plist,遭受毫无意义的“SyntaxError”错误(我可以看到人们有问题),并依赖于删除app.json(你可能不希望这样做)来正确更新弹出的expo项目。
最好只管理自己的脚本解决方案进行版本控制。
1.您可以从下面的gist链接复制节点脚本,以在单个命令中更新以下文件:

  • package.json
  • android/app/build.gradle
  • ios/info.plist
  • ios/app.xcodeproj/project.pbxproj

友情链接:https://gist.github.com/uxinnuendo/1be49a8faec7031044a87dcf79234cbd
1.保存到您的根项目文件夹,并参考代码注解,根据您的项目更新路径引用。
1.然后运行:$ node patch.js
1.修改正则表达式模式以满足您的项目配置文件,因为这可能会因您的react native / expo版本而异。某些项目可能会在版本号上使用双引号等。
该脚本目前只处理“补丁”版本控制,并且基于以下整数版本格式,您可以根据需要修改这两种格式。
[SDK版本:xx][主版本:xx][次版本:xxx][补丁版本:**xx**]
例如:330100001

展开查看全部
p5cysglq

p5cysglq9#

如果您正在使用expo并遇到此问题,请转到app.json并将version更改为更高的数字。

  1. {
  2. "expo": {
  3. "name": "nameofapp", // btw dont copy this
  4. "slug": "appslug", // btw dont copy this
  5. "version": "1.0.0", // here is where you change the version
  6. ...
  7. ...
  8. ...
  9. }
  10. }

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

  1. {
  2. ...
  3. "name": "appname", // btw dont copy this
  4. "version": "2.0.0", // here is where you change the version
  5. ...
  6. "android": {
  7. "versionCode": 2,
  8. ...
  9. }
  10. ...
  11. }

展开查看全部

相关问题