简体   繁体   中英

Expo React-Native Android build not updating Version Code for Google Play

I built a React-Native android app and uploaded to Google Play, which worked fine.

Now I have a new build I am trying to upload (had no issues uploading to itunes Connect), and Google Play is giving me this error: "You need to use a different version code for your APK or Android App Bundle because you already have one with version code 1."

After each build, I have updated the version in app.json, and I have tried updating the version in package.json as well. I've done a directory-wide search for 'versionCode' and there are no instances. A directory-wide search of 'version' turned up over 2,000 results, and I scrolled through all of them, and did not see anything specific to android build. And I did NOT have an issue with iOS build.

I have tried publishing the app first using Max Expo XDE, and I am building it in command line with "exp build:android".

I have the following in my 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"
    }
  }
}

and my package.json is as follows (and npm install has been run):

{
  "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"
  }
}

I also experience this issue, I resolved it by adding versionCode to my app.json under android. For instance,

"android": {
"versionCode": 2
}

Notice that the '2' does not have quotation marks.

if you need know more about versionCode, see this documentation.

versionCodeOnAndroid

需要特别将“versionCode”添加到app.json的“android”部分......

If you are using vanilla react native (without expo) then changing app.json won't work. You have to rather go to build.gradle and increase both versionCode and versionName by 1

If you are using expo bare workflow then changing app.json won't work. You have to rather go to android > app > build.gradle and increase both versionCode and versionName by 1

while building and delivering to testflight you need to update version before build. If you're annoyed with this as much as I am, you could use the nodejs simple script, lets call it 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));

According to Deploying to App Stores 1 , you need to follow the instructions from Building Standalone Apps. The "versionCode" is indeed referenced in 2 and it is an option specific to the Android section: 3 .

Using these configurations worked for me:

{
  "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
    }
  }
}

Find complete Guide here: expo documentation and Play Store Documentation .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM