[ 
https://issues.apache.org/jira/browse/CB-8976?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14943866#comment-14943866
 ] 

Rhett Sutphin commented on CB-8976:
-----------------------------------

Here's the {{after_prepare}} hook I use to get Cordova to use the actual 
versionCode I have set in config.xml:

{noformat}
var path = require('path'),
    fs = require('fs');

/**
 * Sets an override value to force the cordova build process to use the actual,
 * specified-in-the-config.xml versionCode.
 */
module.exports = function forceAndroidVersionCode(context) {
  var et = context.requireCordovaModule('elementtree'),
      manifestPath = path.join(context.opts.projectRoot, 'platforms', 
'android', 'AndroidManifest.xml'),
      manifestContents = fs.readFileSync(manifestPath, { encoding: 'utf8' }),
      manifest = et.parse(manifestContents),
      versionCode = manifest.getroot().get('android:versionCode'),
      buildExtrasPath = path.join(context.opts.projectRoot, 'platforms', 
'android', 'build-extras.gradle');

  fs.writeFileSync(buildExtrasPath, "ext.cdvVersionCode=" + versionCode, { 
encoding: 'utf8' });
};
{noformat}

I am also curious about why Cordova changes the versionCode. I searched the 
mailing list, issue tracker, and commit logs but didn't find any reasoning. I 
figure there must be some explanation, but I do not see it.

> platforms/android/build.gradle modifies android versionCode
> -----------------------------------------------------------
>
>                 Key: CB-8976
>                 URL: https://issues.apache.org/jira/browse/CB-8976
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: CLI
>         Environment: Android
>            Reporter: zack dykes
>
> cordova 5.0.0
> platforms/android/build.gradle modifies android versionCode at ln 178
> as I understand it max size for versionCode is (2^31)-1 
> http://stackoverflow.com/a/24246191/126600
> in my config.xml: 
> {code}
> android-versionCode="1385039613"
> {code}
> when I run {{cordova build android}}, I get:
> {code}
> FAILURE: Build failed with an exception.
> * Where:
> Build file 
> '/Users/zackd/dev/code/cordova/cordova-ansr-fat-client/ondeviceresearch/platforms/android/build.gradle'
>  line: 178
> * What went wrong:
> A problem occurred evaluating root project 'android'.
> > For input string: "13850396130"
> {code}
> and build.gradle, ln 178
> {code}
> versionCode cdvVersionCode ?: Integer.parseInt("" + 
> privateHelpers.extractIntFromManifest("versionCode") + "0")
> {code}
> looks like this is appending "0" to my versionCode, producing 13850396130 
> which is larger than max size for android versionCode
> if I mod ln 178 as follows, build succeeds
> {code}
> versionCode cdvVersionCode ?: Integer.parseInt("" + 
> privateHelpers.extractIntFromManifest("versionCode"))
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@cordova.apache.org
For additional commands, e-mail: issues-h...@cordova.apache.org

Reply via email to