Upload failed: You need to use a different version code for your APK because you already have one with version code

蓝咒 提交于 2021-02-05 06:43:15

问题


THE SITUATION:

Sorry in advance if this question has been asked already three times. But none of those solutions are working for me.

I need to upload a new version to Google Play of my Ionic app. The upload process it has always worked fine but this time i get this error:

You need to use a different version code for your APK because you already have one with version code 101078.

THE PUBLISHING PROCESS:

I am not using Android Studio.

To publish the app i was simply building and signing the app through the command line and then upload it in the Google Developer Console.

For a new version i was simply updating the version number in the config.xml before creating the apk.

APP VERSIONS:

Old version: (status published on Google Play) 1.1.7 Code version: 101078

New version: (trying to upload on Google Play) 1.1.10

ATTEMPTS TO RESOLVE:

I have tried to manually set the Code version to higher number. At the moment i have this settings in the ./config.xml:

<widget id="com.myapp.myapp" version="1.1.10" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">

In the file ./platforms/android/AndroidManifest.xml I manually change the settings to:

<manifest android:hardwareAccelerated="true" android:versionCode="101079" android:versionName="1.1.10" package="com.meetinghand.meetinghand" xmlns:android="http://schemas.android.com/apk/res/android">

But after i run cordova build --release android that value is automatically reset to android:versionCode="10110" ...

RUNNING AAPT:

Running the sdk tool aapt on the apk file i get the following:

name='com.myapp.myapp' versionCode='101078' versionName='1.1.7' platformBuildVersionName='6.0-2704002' sdkVersion:'16' targetSdkVersion:'22'

THE QUESTION:

What's going on?

How exactly is the versionCode set? Can I hardcode it? Why, no matter what I do, does the versionCode remain at 101078?

Why is versionName 1.1.7 and not 1.1.10 as it is clearly stated in the config.xml?

I don't know what else can I do.

If you solve this riddle I will build a sculpture in your honor!

Thank you!

EDIT:

In the end i decided to uninstall CrossWalk because didn't strictly need its benefits. In this way the issue was resolved and I could upload the new version.

I could indeed hardcode the code version inside the config.xml as pointed out by @e666:

<widget android-versionCode="101079" id="com.myapp.myapp" version="1.1.10" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">

The versionCode was not overwritten by Crosswalk but was properly set as 101079 and in this way i could upload the apk as new version.

If you still want to keep Crosswalk and upload the new version you can do it by switching to Advanced Mode in the Google Developer Console. Keep in mind the Crosswalk will export two apk (armv7 and x86) and you will need to upload both.

For more reference about how to do you may check out this answer:

What does this Google Play APK publish error message mean?


回答1:


It is normal that cordova is overriding your changes on AndroidManifest.xml The proper solution is to put the version in config.xml.

From cordova docs, the version code is calculated based on the version if you don't specify a versionCode explicitely. It will be :

versionCode = MAJOR * 10000 + MINOR * 100 + PATCH

So the android:versionCode="10110" is normal.

You can specify a version code explicitely in config.xml with android-versionCode

Also you should try to clean all your platform folder if it is not updating it. Maybe what you are seeing is an old version of your apk.

I forgot : here is the link to cordova docs : https://cordova.apache.org/docs/en/6.x/guide/platforms/android/index.html#setting-the-version-code

And for the old version code 101078 maybe you were using a plugin like Crosswalk.




回答2:


To resolve this issue just do following steps and you will get your .apk file ready with issue resolved.

Step 1: Clean cordova build

  $ cordova clean

Step 2: Again generate "android-release-unsigned.apk" file

  $ ionic cordova build --release android

Step 3: To sign the unsigned APK, run the jarsigner tool which is also included in the JDK:

  $ jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore my-release-key.keystore path-to-your-app/apk/android-release-unsigned.apk alias_name

Step 4: You need to run the zip align tool to optimize the APK

$ zipalign -v 4 path-to-your-app/apk/android-release-unsigned.apk path-to-your-app/apk/your-app-name.apk

Or

$ path-to-zipalign/zipalign -v 4 path-to-your-app/apk/android-release-unsigned.apk path-to-your-app/apk/your-app-name.apk


来源:https://stackoverflow.com/questions/38877980/upload-failed-you-need-to-use-a-different-version-code-for-your-apk-because-you

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!