What causes this Android APK Upload error: "Non-upgradable APK"

I got able to resolve this issue:-

The issue was with the versioncode - I am sure you have not defined any version code in your App and it is getting generated by this formula:

 versionCode = MAJOR * 10000 + MINOR * 100 + PATCH

But sometimes auto generated versioncode value of the latest release becomes smaller than the previous release (in your case 10403 < 104028) and that's why it shows non-upgradable APK.

What you need to do is:-

In your config.xml in tag add versioncode like below:-

android-versionCode="104280" 

104280 will work for you as it is greater than older version.

Now get it published without any error.

Thanks Sanny


I ran into a similar problem but was able to solve it with the following Node script used as part of my continuous deployment pipeline.

Note:

This reads from a VERSION.md file that contains the current app version.

It may also be run with the --version argument to only update the current version in config.xml without setting the build versions.

#!/usr/bin/env node

var fs = require('fs');
var xml2js = require('xml2js');
const cliArgs = require('command-line-args');
const options = cliArgs([
    {name: 'version', type: Boolean}
]); 

// Read config.xml
var xml = fs.readFileSync('config.xml', 'utf8');

// Parse XML to JS Obj
xml2js.parseString(xml, function (err, result) {
    if(err) {
        return console.log(err);
    }

    // Get JS Obj
    var obj = result;
    const version = fs.readFileSync('VERSION.md', 'utf8');

    if (options.version){
        // Write current version
        obj['widget']['$']['version'] = version;
    } else {
        // Increment build numbers (separately for iOS and Android)
        obj['widget']['$']['ios-CFBundleVersion'] = version;
        // remove all periods to create an integer for Android
        const [major, minor, patch] = version.split('.')
        obj['widget']['$']['android-versionCode'] = major+pad_number(minor)+pad_number(patch);
    }

    // Build XML from JS Obj
    var builder = new xml2js.Builder();
    var xml = builder.buildObject(obj);

    // Write config.xml
    fs.writeFile('config.xml', xml, function(err) {
        if(err) {
            return console.log(err);
        }
        
        console.log('Build number successfully incremented');
    });

});

/**
 * Pad a number with prepending zeros if less than 10
 * @see [Javascript function to pad a string](https://stackoverflow.com/questions/2686855/is-there-a-javascript-function-that-can-pad-a-string-to-get-to-a-determined-leng)
 */
function pad_number(orig) {
    return ("00"+orig).slice(-2);
}

I'm using VS-TACO and ran into this problem.

To slightly clarify Sanny's answer which fixed the issue for me. Apparently, somewhere along the way the android-versionCode was calculated using this formula:

MAJOR * 100000 + MINOR * 1000 + PATCH * 10

but now it is getting calculated using the version Sanny shows:

MAJOR * 10000 + MINOR * 100 + PATCH

So for example if your version was 1.3.1 android-versionCode was calculated as "103010"

now you change the version to 1.3.2 and it is calculated the new way so the version is "10302" which is less than "103010".

So to work around this issue (I guess forever if the android version keeps getting calculated the new way) you can add the version tag to your config.xml:

<?xml version="1.0" encoding="utf-8"?>
<widget android-versionCode="103020" ...

or you can go into Visual Studio and use the visual editor for config.xml, go to the "Android" section and change the "Version Code:" value.