52

I'm getting this error when uploading my Phonegap app to the Google Play Developer Console:

Your APK's version code needs to be higher than 2.

How can I fix this?

the
  • 21,007
  • 11
  • 68
  • 101

16 Answers16

77

If you're directly using Gradle, or indirectly through Android Studio:

I fixed it by editing the version number inside of the build.gradle file! There is a small banner at the bottom of the android.manifest file that says "these changes are being overwritten by the build.gradle file."

the
  • 21,007
  • 11
  • 68
  • 101
user3546740
  • 794
  • 6
  • 2
  • 4
    If you're using Android Studio use this answer. – HighLife May 26 '14 at 00:31
  • 4
    You may even remove `versionCode` and `versionName` from `build.gradle`. If removed, AndroidStudio will revert back to your `AndroidManifest.xml` – Ivo Renkema Mar 29 '15 at 12:35
  • 1
    @IvoRenkema your comment could be an actual answer, why not make it one? The obvious advantage is only having to remember to update version numbers in one file after that... – Kev Oct 22 '15 at 12:15
27

enter image description here

Please see attached snap of Android Studio which should help.

Vijay
  • 2,021
  • 4
  • 24
  • 33
  • 6
    `versionCode` must increase by at least 1, however, `versionName` can increase by .1 (or whatever else) since that is what the end user sees. – Micro Sep 22 '15 at 17:41
  • 3
    Actually, versionName doesn't even have to increase, if you don't want it to. – Kev Oct 22 '15 at 12:14
15

Increase the version code to 3 by changing versionCode in your AndroidManifest.xml:

<android xmlns:android="http://schemas.android.com/apk/res/android">
        <tool-api-level>10</tool-api-level>
        <manifest android:versionCode="3" android:versionName="0.1.1" android:installLocation="preferExternal"/>
        <uses-sdk android:maxSdkVersion="10" android:minSdkVersion="7" android:targetSdkVersion="10"/>
</android>
the
  • 21,007
  • 11
  • 68
  • 101
Hamed Baatour
  • 6,664
  • 3
  • 35
  • 47
  • 3
    in **Android Studio** .5+ ... **see next answer** – Fattie Jun 19 '14 at 12:38
  • when i changed it to this it gives me this error Upload failed You need to use a different version code for your APK because you already have one with version code 3. – Ahmad Arslan Jul 16 '14 at 04:37
8

Use aapt to verify your APK version:

aapt dump badging myapp.apk

It will tell you to increase the versionCode in AndroidManifest.xml, e.g.

  <manifest android:versionCode="3">
the
  • 21,007
  • 11
  • 68
  • 101
6

Had the same problem and solved it by changing the following values in the build.gradle file in the Module: app

defaultConfig {
        applicationId //app package goes here
        minSdkVersion 10
        targetSdkVersion 21
        **versionCode 2
        versionName "1.1"**
        signingConfig //name of keystore goes here
    }

This is the way Android Studio keeps track of the versioning for each app.

Alternatively, for the noobs, you can access these settings by clicking on the settings of the app, and navigating to the Flavors tab. There you can amend certain settings such as the versionCode and the versionName.

Hope this helps :)

Michele La Ferla
  • 6,775
  • 11
  • 53
  • 79
4

When you are ready to deploy your app to an APK, in JDeveloper go to Application -> Deploy -> New Deployment Profile. Set Profile Type to ADF Mobile for Android, pick a name and click OK. In the next window pick the Android options and change the Version Code. That's what Google Play didn't like (because you already had an app with the same version code). That's how I resolved this issue.

Ivan
  • 41
  • 2
4

People at android and your users need to just keep track of all the updates so it's required for you to mention the version by updating versionCode and versionName

Here is how to fix the problem:

EARLIER

defaultConfig {
    applicationId "com.example.random.projectname"
    minSdkVersion 15
    targetSdkVersion 24
    versionCode 1
    versionName "1.0"
}

NOW

defaultConfig {
    applicationId "com.example.random.projectname"
    minSdkVersion 15
    targetSdkVersion 24
    versionCode 2
    versionName "1.0.1"
}

Remember

  • versionName is what is displayed at bottom of Long Description for the app's user
  • While versionCode is for developer's and google's need and has to be incremented by one always for every new versionName even when you change versionName from v1.0.5 to v1.0.6
Slick Slime
  • 649
  • 7
  • 19
3

I suppose that you already have a version 2 uploaded to your dev console. Simply increase the version code (note: NOT version name!) to 3, rebuild your APK and you are fine.

Goddchen
  • 4,459
  • 4
  • 33
  • 54
  • 6
    I did not know how to increase the version code that Google's console asked me about. Otherwise I wouldn't have asked this question here... – the Mar 23 '13 at 23:50
3

I had this issue for a while and it stumped me. I tried re-importing project. Taking the project into Android Studio from Eclipse. Everything. And what I found to work is that you have to increase the version code by 1 value. You don't have to change the version name. And before you export the apk file. Make sure you build the project at least once. So the new version code is realized.

Randolph
  • 951
  • 2
  • 11
  • 24
3

I found that if you are using Android Studio, you need to update the version code in the build.gradle file. For example:

defaultConfig {
    applicationId "app.myapp"
    minSdkVersion 14
    targetSdkVersion 20
    versionCode 2
    versionName "1.0.0"
}

...

the
  • 21,007
  • 11
  • 68
  • 101
droid-zilla
  • 536
  • 7
  • 8
  • This is what worked for me, none of the other suggestions did. Upvoted, and thanks for your answer! – Kreg Aug 23 '16 at 00:19
3

Had the same problem. Changing the version wasn't helpful. For Android builds you can add versionCode to your config.xml and state the version.

    xmlns:gap = "http://phonegap.com/ns/1.0"
    id        = "xxx.xxxxxx"
    versionCode = "415" 
    version   = "1.0.11">

Check http://docs.build.phonegap.com/en_US/3.1.0/configuring_basics.md.html#The%20Basics

the
  • 21,007
  • 11
  • 68
  • 101
BrunoMartins
  • 191
  • 1
  • 3
2

In Android studio I was only able to get this to work by changing the versionCode in the app file.

android {
    compileSdkVersion 19
    buildToolsVersion '19.1.0'
    defaultConfig {
        applicationId 'xxxxxxxxxxxxxxx'
        minSdkVersion 14
        targetSdkVersion 19
        versionCode 3
        versionName '1.1'
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
    }
}
Michele La Ferla
  • 6,775
  • 11
  • 53
  • 79
user2848810
  • 1,187
  • 1
  • 8
  • 12
2

The solution for me was to edit config.xml and change the 'version' property.

I tried editing my AndroidManifest.xml (every version I could find) and changed the versionCode and versionName values. Some of the AndroidManifest.xml files were overwritten with the original values, some were not overwritten. Regardless, the apk version was remaining at '1'.

I looked in config.xml several times, but neither versionCode and versionName exist within. I finally decided to change the 'version' value in config.xml, rebuilt, and my apk now has the new, correct, version number.

In config.xml:

Old 'version' property: "version=0.0.1"

New 'version' property: "version=0.0.2"

It should be noted that I am not using Eclipse or Android Studio ... just a text editor and running a manual build. Now when I run

aapt dump badging [apk name]

I am seeing an updated versionCode and versionName... specifically, I see this:

versionCode='2' versionName='0.0.2'

...and I can now upload my apk successfully to the Play store once again.

Michele La Ferla
  • 6,775
  • 11
  • 53
  • 79
Phrank
  • 73
  • 2
1
appt dump badging myapp.apk

This command works in checking the built apk version. but to and old trick fixed this problem, even if I incremented the version. Try to clean the workspace and build again.

the
  • 21,007
  • 11
  • 68
  • 101
1

easy way to resolve it is click on Build > Edit Flavors...

enter image description here

change version code and version name

enter image description here

click ok and done

shim
  • 9,289
  • 12
  • 69
  • 108
0

For my Cordova built app, the Gradle file didnt have the static code. It was picked using Android Manifest like this -

defaultConfig {
versionCode cdvVersionCode ?: Integer.parseInt("" + privateHelpers.extractIntFromManifest("versionCode") + "0")
applicationId privateHelpers.extractStringFromManifest("package")

if (cdvMinSdkVersion != null) {
    minSdkVersion cdvMinSdkVersion
}

}

I tried changing the version code in the manifest file, but no luck.

Not a good thing to do, but out of hurry I did this -

defaultConfig {
versionCode cdvVersionCode ?: (Integer.parseInt("" + privateHelpers.extractIntFromManifest("versionCode") + "0") + 2)
applicationId privateHelpers.extractStringFromManifest("package")

if (cdvMinSdkVersion != null) {
    minSdkVersion cdvMinSdkVersion
}

}

Note: For Cordova built apps, you need to make changes in the Gradle Scripts > File which says - "build.gradle (Module:android)"

Lakshay Dulani
  • 1,710
  • 2
  • 18
  • 45