Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

buildNumber in mobile-config.js does not change versioncode in android build. #6978

Closed
jb1999 opened this issue May 5, 2016 · 17 comments
Closed

Comments

@jb1999
Copy link

@jb1999 jb1999 commented May 5, 2016

_2 Upvotes_ Hi -

I'm trying to upload a new version of my app to the play store and ran into the "You need to use a different version code for your APK because you already have one with version code" error. Looking closer I found that the versioncode was not being updated with the buildNumber specified in the mobile-config.js. I reproduced the issue using the vanilla meteor todos app, repro steps below:

$ git clone https://github.com/meteor/todos 
$ cd todos
$ meteor --version
Meteor 1.3               
$ meteor npm install --save faker # to address build error "unable to resolve some modules"
$ meteor npm install --save autoprefixer # to fix "error: Can't load npm module 'autoprefixer' from ..."

#--------------------- baseline -------------------#
$ meteor build ../buildtodos --server http://www.whatever.org
$ cp ../buildtodos/android/project/build/outputs/apk/android-armv7-release-unsigned.apk ../buildtodos/android/release-unsigned.apk # for some reason the apk file did not get copied to the top build directory

$ /Users/justme/Library/Android/sdk/build-tools/23.0.2/aapt dump badging ../buildtodos/android/release-unsigned.apk 
package: name='com.idvqze4o4fmojp1vxyybb' versionCode='12' versionName='0.0.1' platformBuildVersionName='6.0-2438415'
sdkVersion:'14'
targetSdkVersion:'23'
[snip]

The buildNumber is not specified in the original mobile-config.js and defaults to versionCode='12'

To repro issue added buildNumber and updated version to '1.0.0'

#--------------------- modified mobile-config.js with version/build # -------------------#
$ git diff
diff --git a/mobile-config.js b/mobile-config.js
index e256b90..bc9be1a 100644
--- a/mobile-config.js
+++ b/mobile-config.js
@@ -7,7 +7,8 @@ App.info({
   author: 'Percolate Studio Team',
   email: 'us@percolatestudio.com',
   website: 'http://percolatestudio.com',
-  version: '0.0.1',
+  version: '1.0.0',
+  buildNumber: '1'
 });

 App.icons({
diff --git a/package.json b/package.json
index 30a0235..be6f62e 100644
--- a/package.json
+++ b/package.json
@@ -8,8 +8,8 @@
     "chimp-watch": "chimp --ddp=http://localhost:3000 --watch --mocha --path=tests"
   },
   "dependencies": {
-    "autoprefixer": "^6.3.1",
-    "faker": "^3.0.1"
+    "autoprefixer": "https://registry.npmjs.org/autoprefixer/-/autoprefixer-6.3.4.tgz",
+    "faker": "https://registry.npmjs.org/faker/-/faker-3.1.0.tgz"
   },
   "devDependencies": {
     "eslint": "^2.3.0",

$ meteor build ../buildtodos --server http://www.whatever.org
$ /Users/justme/Library/Android/sdk/build-tools/23.0.2/aapt dump badging ../buildtodos/android/release-unsigned.apk
package: name='com.idvqze4o4fmojp1vxyybb' versionCode='12' versionName='1.0.0' platformBuildVersionName='6.0-2438415'
sdkVersion:'14'
targetSdkVersion:'23'

versionName updates correctly to 1.0.0 but versionCode is unchanged

$ find ../buildtodos/android -type f -print |xargs grep -I -i versioncode
../buildtodos/android/project/AndroidManifest.xml:<manifest android:hardwareAccelerated="true" android:versionCode="1" android:versionName="1.0.0" package="com.idvqze4o4fmojp1vxyybb" xmlns:android="http://schemas.android.com/apk/res/android">
../buildtodos/android/project/build/intermediates/exploded-aar/android/CordovaLib/unspecified/release/aapt/AndroidManifest.xml:    android:versionCode="1"
../buildtodos/android/project/build/intermediates/exploded-aar/android/CordovaLib/unspecified/release/AndroidManifest.xml:    android:versionCode="1"
../buildtodos/android/project/build/intermediates/exploded-aar/org.xwalk/xwalk_core_library/17.46.448.10/AndroidManifest.xml:    android:versionCode="1"
../buildtodos/android/project/build/intermediates/manifests/full/armv7/release/AndroidManifest.xml:    android:versionCode="12"
../buildtodos/android/project/build/intermediates/manifests/full/x86/release/AndroidManifest.xml:    android:versionCode="14"
../buildtodos/android/project/build/intermediates/res/merged/armv7/release/xml/config.xml:<widget android-versionCode="1" id="com.idvqze4o4fmojp1vxyybb" ios-CFBundleVersion="1" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
../buildtodos/android/project/build/intermediates/res/merged/x86/release/xml/config.xml:<widget android-versionCode="1" id="com.idvqze4o4fmojp1vxyybb" ios-CFBundleVersion="1" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
../buildtodos/android/project/build/outputs/logs/manifest-merger-armv7-release-report.txt:  android:versionCode
../buildtodos/android/project/build/outputs/logs/manifest-merger-x86-release-report.txt:    android:versionCode
../buildtodos/android/project/build.gradle:    // Sets the versionCode to the given value.
../buildtodos/android/project/build.gradle:    if (!project.hasProperty('cdvVersionCode')) {
../buildtodos/android/project/build.gradle:        cdvVersionCode = null
../buildtodos/android/project/build.gradle:ext.cdvVersionCode = cdvVersionCode == null ? null : Integer.parseInt('' + cdvVersionCode)
../buildtodos/android/project/build.gradle:    println('cdvVersionCode=' + cdvVersionCode)
../buildtodos/android/project/build.gradle:    println('computedVersionCode=' + android.defaultConfig.versionCode)
../buildtodos/android/project/build.gradle:        println('computed' + flavor.name.capitalize() + 'VersionCode=' + flavor.versionCode)
../buildtodos/android/project/build.gradle:        versionCode cdvVersionCode ?: Integer.parseInt("" + privateHelpers.extractIntFromManifest("versionCode") + "0")
../buildtodos/android/project/build.gradle:                versionCode defaultConfig.versionCode + 2
../buildtodos/android/project/build.gradle:                versionCode defaultConfig.versionCode + 4
../buildtodos/android/project/build.gradle:    } else if (!cdvVersionCode) {
../buildtodos/android/project/build.gradle:      // Vary versionCode by the two most common API levels:
../buildtodos/android/project/build.gradle:        defaultConfig.versionCode += 9
../buildtodos/android/project/build.gradle:        defaultConfig.versionCode += 8
../buildtodos/android/project/cordova/lib/AndroidManifest.js:AndroidManifest.prototype.getVersionCode = function() {
../buildtodos/android/project/cordova/lib/AndroidManifest.js:    return this.doc.getroot().attrib['android:versionCode'];
../buildtodos/android/project/cordova/lib/AndroidManifest.js:AndroidManifest.prototype.setVersionCode = function(versionCode) {
../buildtodos/android/project/cordova/lib/AndroidManifest.js:    this.doc.getroot().attrib['android:versionCode'] = versionCode;
../buildtodos/android/project/cordova/lib/build.js:        versionCode: String,
../buildtodos/android/project/cordova/lib/build.js:    if (options.argv.versionCode)
../buildtodos/android/project/cordova/lib/build.js:        ret.extraArgs.push('-PcdvVersionCode=' + options.argv.versionCode);
../buildtodos/android/project/cordova/lib/build.js:    console.log('    \'--versionCode=#\': Override versionCode for this build. Useful for uploading multiple APKs. Requires --gradle.');
../buildtodos/android/project/cordova/lib/prepare.js:        .setVersionCode(platformConfig.android_versionCode() || default_versionCode(platformConfig.version()))
../buildtodos/android/project/cordova/lib/prepare.js:// Consturct the default value for versionCode as
../buildtodos/android/project/cordova/lib/prepare.js:function default_versionCode(version) {
../buildtodos/android/project/cordova/lib/prepare.js:    var versionCode = 0;
../buildtodos/android/project/cordova/lib/prepare.js:        versionCode += +nums[0] * 10000;
../buildtodos/android/project/cordova/lib/prepare.js:        versionCode += +nums[1] * 100;
../buildtodos/android/project/cordova/lib/prepare.js:        versionCode += +nums[2];
../buildtodos/android/project/cordova/lib/prepare.js:    return versionCode;
../buildtodos/android/project/cordova/node_modules/cordova-common/src/ConfigParser/ConfigParser.js:    android_versionCode: function() {
../buildtodos/android/project/cordova/node_modules/cordova-common/src/ConfigParser/ConfigParser.js:        return this.doc.getroot().attrib['android-versionCode'];
../buildtodos/android/project/cordova/node_modules/cordova-common/src/ConfigParser/README.md:    android_versionCode()
../buildtodos/android/project/cordova-plugin-crosswalk-webview/idvqze4o4fmojp1vxyybb-xwalk.gradle:                    versionCode defaultConfig.versionCode + 6
../buildtodos/android/project/cordova-plugin-crosswalk-webview/idvqze4o4fmojp1vxyybb-xwalk.gradle:                    versionCode defaultConfig.versionCode + 9
../buildtodos/android/project/CordovaLib/AndroidManifest.xml:      package="org.apache.cordova" android:versionName="1.0" android:versionCode="1">
../buildtodos/android/project/CordovaLib/build/intermediates/bundles/debug/aapt/AndroidManifest.xml:    android:versionCode="1"
../buildtodos/android/project/CordovaLib/build/intermediates/bundles/debug/AndroidManifest.xml:    android:versionCode="1"
../buildtodos/android/project/CordovaLib/build/intermediates/bundles/release/aapt/AndroidManifest.xml:    android:versionCode="1"
../buildtodos/android/project/CordovaLib/build/intermediates/bundles/release/AndroidManifest.xml:    android:versionCode="1"
../buildtodos/android/project/res/xml/config.xml:<widget android-versionCode="1" id="com.idvqze4o4fmojp1vxyybb" ios-CFBundleVersion="1" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">

From looking through the Cordova build files android/project/build/intermediates/manifests/full/*/release/AndroidManifest.xml is not being updated correctly even though config.xml has android-versionCode set correctly.

This was all working till recently - I upgraded to Meteor 1.3.2.4 not sure if that changed something.

thanks!!!

@dude-awesome
Copy link

@dude-awesome dude-awesome commented May 5, 2016

+1

@jb1999
Copy link
Author

@jb1999 jb1999 commented May 6, 2016

One workaround is to create build-extras.gradle with an appropriate cdvVersionCode but this would be reverting back to the pre- buildNumber process.

# executed in the todos directory in repro instructions above
$ mkdir -p cordova-build-override/platforms/android
$ echo cdvVersionCode = \'-1\'  >  cordova-build-override/platforms/android/build-extras.gradle
$ meteor build ../buildtodos --server http://www.whatever.org
$ cp ../buildtodos/android/project/build/outputs/apk/android-armv7-release-unsigned.apk ../buildtodos/android/release-unsigned.apk
$ /Users/justme/Library/Android/sdk/build-tools/23.0.2/aapt dump badging ../buildtodos/android/release-unsigned.apk 
package: name='com.idvqze4o4fmojp1vxyybb' versionCode='1' versionName='1.0.0' platformBuildVersionName='6.0-2704002'
sdkVersion:'14'
targetSdkVersion:'23'
[snip]

In the example above, I wanted versionCode as 1, but the build process was adding 2 to the versionCode, I set cdvVersionCode to '-1' so that final versionCode was '1'

@timbrandin
Copy link

@timbrandin timbrandin commented May 27, 2016

@jb1999 I can't get your workaround to work, only one time it did, but I can't confirm the reason for it.

@timbrandin
Copy link

@timbrandin timbrandin commented May 27, 2016

I'm also using crosswalk, if that makes any difference.

@miri-am
Copy link

@miri-am miri-am commented May 27, 2016

I am also having this problem when submitting an app. However, after I ran the exact same build process a second time it works. I dont know the reason for this, but for me it does work every second build.

@timbrandin
Copy link

@timbrandin timbrandin commented May 27, 2016

Ah Alright, so double it works

@jb1999
Copy link
Author

@jb1999 jb1999 commented May 27, 2016

Hmm - I just uploaded my app to the play store and did not have any issues with the workaround. Glad the second time worked perhaps some files are not being overwritten the first time(?).

@timbrandin
Copy link

@timbrandin timbrandin commented May 28, 2016

Yeah, for me it's not like every time it works, I'm just getting used to
building and building until the versioncode gets right, very frustrating!

2016-05-27 18:56 GMT+02:00 jb1999 notifications@github.com:

Hmm - I just uploaded my app to the play store and did not have any issues
with the workaround. Glad the second time worked perhaps some files are not
being overwritten the first time(?).


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#6978 (comment), or mute
the thread
https://github.com/notifications/unsubscribe/ABouelFo27ynu4RrrxtYALrJhFnzGMqoks5qFyJAgaJpZM4IYWeP
.

Cheers,
// Tim Brandin @timbrandin https://twitter.com/#!/timbrandin
http://timbrandin.com
http://studiointeract.com

@atulmy
Copy link

@atulmy atulmy commented Nov 23, 2016

This problem still exists. Anyone found any good solution!?

@jackkav
Copy link
Contributor

@jackkav jackkav commented Nov 24, 2016

#7205

It appears to fixed in 1.4.2

Set buildNumber in your mobile config, or update your version before you build and let it generate one for you. Be warned that generating versionCode would not work well if you have already published an app with a build number with an 8 or 28 appended and it would be best to just manage the buildNumber manually in you mobile-config.js

apache/cordova-android@9224ab1

@atulmy
Copy link

@atulmy atulmy commented Nov 24, 2016

@jackkav thanks, buildNumber worked.

App.info({
    id: '...',
    name: '...',
    version: "1.8",
    buildNumber: '108008'
});
@abernix
Copy link
Member

@abernix abernix commented Nov 24, 2016

I do believe this is fixed in 1.4.2, however as @jackkav outlined in #7205 (comment), there could be some issues with that. I'm closing this in favor of that issue for wrapping up the conversation, but it does appear that this is fixed if you actually set buildNumber.

It is best if you manage your build number manually due to some strange decisions Cordova (itself) makes when building for various architectures. If you read the Cordova source code (apache/cordova-android@dc57941) you might understand why better, but it's still a bit unclear. Again, use buildNumber to provide the number as part of your build process. If you do this, using Meteor 1.4.2 or higher (which was upgraded for Cordova 6.2) you will avoid all the extra changes that Cordova tries to intelligently make and it will just use your version.

Thanks for reporting this issue originally. And thank you @jackkav for your followthrough on this.

@JWPapi
Copy link

@JWPapi JWPapi commented Dec 7, 2016

I used buildNumber, but it still didnt work. I dont even know whats the version code

@jackkav
Copy link
Contributor

@jackkav jackkav commented Dec 7, 2016

It gets set in your AndroidManifest.xml during the meteor build process. It should match your buildNumber.

@c316
Copy link

@c316 c316 commented Jan 11, 2017

@atulmy The buildNumber didn't do anything for me. For it to take the change I had to make an actual change to my code, then the versionCode updated in my app.

@rafaelrglima
Copy link

@rafaelrglima rafaelrglima commented Feb 7, 2017

I am having the same problem here. I can change the buildNumber or the version and do the apk build again, but still can not upload apk because of the buildNumber is the same. But on the androidManifest the version is updated normally. So I am thinking is something else after the build process.

@abernix
Copy link
Member

@abernix abernix commented Feb 9, 2017

Please read my comments here #6978 (comment) and the related thread here #7205 (comment) which essentially provides an explanation, reasoning and a solution. This particular issue is closed.

@meteor meteor locked and limited conversation to collaborators Feb 9, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
You can’t perform that action at this time.