[英]Expo React-Native Android build not updating Version Code for Google Play
我構建了一個 React-Native android 應用程序並上傳到 Google Play,效果很好。
現在我有一個我正在嘗試上傳的新版本(上傳到 iTunes Connect 沒有問題),Google Play 給我這個錯誤:“你需要為你的 APK 或 Android App Bundle 使用不同的版本代碼,因為你已經有了一個版本代碼為 1。”
每次構建后,我都會更新 app.json 中的版本,並且我也嘗試過更新 package.json 中的版本。 我已經對“versionCode”進行了目錄范圍的搜索,但沒有實例。 對“版本”的目錄范圍搜索出現了 2,000 多個結果,我滾動瀏覽了所有結果,並沒有看到任何特定於 android build 的內容。 而且我對 iOS 構建沒有任何問題。
我曾嘗試使用 Max Expo XDE 首先發布該應用程序,並且我正在使用“exp build:android”在命令行中構建它。
我的 app.json 中有以下內容:
{
"expo": {
"name": "Placeholder",
"sdkVersion": "27.0.0",
"privacy": "unlisted",
"orientation": "portrait",
"icon": "./assets/img/AppIcon.png",
"version": "0.3.4",
"ios": {
"bundleIdentifier": "com.placeholder.placeholder"
},
"android": {
"package": "com.placeholder.placeholder"
}
}
}
我的 package.json 如下(並且 npm install 已經運行):
{
"name": "placeholder",
"version": "0.2.0",
"private": true,
"devDependencies": {
"jest-expo": "~27.0.0",
"react-native-scripts": "1.14.0",
"react-test-renderer": "16.3.1"
},
"main": "./node_modules/react-native-scripts/build/bin/crna-entry.js",
"scripts": {
"start": "react-native-scripts start",
"eject": "react-native-scripts eject",
"android": "react-native-scripts android",
"ios": "react-native-scripts ios",
"test": "jest"
},
"jest": {
"preset": "jest-expo"
},
"dependencies": {
"axios": "^0.18.0",
"expo": "^27.0.1",
"native-base": "^2.4.3",
"react": "16.3.1",
"react-native": "https://github.com/expo/react-native/archive/sdk-27.0.0.tar.gz",
"react-native-svg": "^6.3.1",
"react-navigation": "^2.0.0",
"redux-thunk": "^2.2.0",
"socket.io-client": "^2.1.0"
}
}
我也遇到了這個問題,我通過在android下的app.json中添加versionCode解決了這個問題。 例如,
“安卓”: {
“版本代碼”:2
}
請注意,“2”沒有引號。
如果您需要了解有關 versionCode 的更多信息,請參閱此文檔。
需要特別將“versionCode”添加到app.json的“android”部分......
如果您使用的是原生反應原生(沒有博覽會),那么更改 app.json 將不起作用。 您必須寧願去 build.gradle 並將 versionCode 和 versionName 都增加 1
如果您使用的是 expo 裸工作流,那么更改 app.json 將不起作用。 你必須寧願去android > app > build.gradle
並將 versionCode 和 versionName 都增加 1
在構建和交付到 testflight 時,您需要在構建之前更新版本。 如果你和我一樣對此感到惱火,你可以使用 nodejs 簡單腳本,我們稱之為 build.js:
'use strict';
const fs = require('fs');
const { exec } = require('child_process');
let config = require('./app.json');
let t = new Date().getTime();
let backup = 'app.' + t + '.json';
// make some backup
fs.writeFile(backup, JSON.stringify(config));
let v = config.expo.version;
v = v.split('.');
let x = parseInt(v[v.length - 1]);
// add to last part of version, update to your needs
v[v.length - 1] = (x + 1);
config.expo.version = v.join('.');
// write new config
fs.writeFile('app.json', JSON.stringify(config, null, 2));
使用這些配置對我有用:
{
"expo": {
"name": "APP_NAME",
"description": "APP_DESCRIPTION",
"slug": "SLUG_NSME",
"version": "1.1.0",
"orientation": "portrait",
"updates": {
"fallbackToCacheTimeout": 0
},
"assetBundlePatterns": ["**/*"],
"android": {
"package": "com.company_name.project_name",
"versionCode": 2 // just change/add this line
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.