简体   繁体   中英

Gradle throwing error on version numbers in cordova config.xml

The config.xml file of my ionic/cordova project has the following set

android-versionCode="201504231751" ios-CFBundleVersion="201504231752"

When I try building for android using "cordova build android" gradle throws me an error saying :

FAILURE: Build failed with an exception. * Where: Script 'E:\\Workspaces\\xxx\\xxx\\platforms\\android\\CordovaLib\\cordova.gradle' line: 128 * What went wrong: A problem occurred evaluating root project 'android'.

For input string: "201504231750" * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

Line 128 on \\CordovaLib\\cordova.gradle is a ParseInt. My assumption is that the string cannot be converted to an integer and thus the problem.

When I change the string to be a simple integer it works.

I need the version to be a timestamp. How do I overcome this error?

I am on a windows 7 machine. What's strange is that the same code base gets built for android on a mac machine.

Thanks smaira

I ran into this problem and "solved" it with a hack that makes me a little uncomfortable, but which works. I noticed that the string in the error message has a zero appended to the end (eg, I set the versionCode to 2015073001, but the error message contains 2015073001 0 ).

Honestly, I don't know what this code is doing (or even what language it is), but it seems a little strange to me to modify the provided input. I modified the code starting on line 177 of platforms/android/build.gradle from:

    defaultConfig {
        versionCode cdvVersionCode ?: Integer.parseInt("" + privateHelpers.extractIntFromManifest("versionCode") + "0")
        if (cdvMinSdkVersion != null) {
            minSdkVersion cdvMinSdkVersion
        }
    }

to

    defaultConfig {
        versionCode cdvVersionCode ?: Integer.parseInt("" + privateHelpers.extractIntFromManifest("versionCode"))
        if (cdvMinSdkVersion != null) {
            minSdkVersion cdvMinSdkVersion
        }
    }

@smaira

I was getting the same error as well.

201504231750 is not a valid int in java, it exceeds the bounds of an int.

I would recommend using a unix timestamp instead. I'm doing something similar to the following in my bash script (on a mac, don't know what the windows equivalent is):

timestamp=$(date +%s)
cordova build android -- --gradleArg=-PcdvVersionCode=$timestamp

Try to override the property, flop your own closure

privateHelpers.extractIntFromManifest = { name -> doExtractIntFromManifest(name) }

with

ext.privateHelpers.extractIntFromManifest = { name -> idontwantyourintversionmethod(name) }

@Al Jacinto I did try and override the property but I think I'm not doing it correct.

In cordova.gradle ,

I replaced

privateHelpers.extractIntFromManifest = { name -> doExtractIntFromManifest(name) }

with

privateHelpers.extractIntFromManifest = { name -> dontExtractIntFromManifest(name) }

I then duplicated the extractIntFromManifest method, renamed to dontExtractIntFromManifest and removed the parseInt from the return as follows

def dontExtractIntFromManifest(name) { def manifestFile = file(android.sourceSets.main.manifest.srcFile) def pattern = Pattern.compile(name + "=\\"(\\\\d+)\\"") def matcher = pattern.matcher(manifestFile.getText()) matcher.find() return matcher.group(1) }

but when I tried building it I got the same error. However, I realized that the error was coming from build.gradle while I was modifying cordova.gradle. So I opened build.gradle and changed the defaultConfig

defaultConfig { //versionCode cdvVersionCode ?: Integer.parseInt("" + privateHelpers.extractIntFromManifest("versionCode") + "0") //SMI:Trying to get rid of the error versionCode cdvVersionCode ?: privateHelpers.extractIntFromManifest("versionCode") + "0" if (cdvMinSdkVersion != null) { minSdkVersion cdvMinSdkVersion } }

but that didn't help either. Now I get a different error message which is

`* Where: Build file '/Users/IOMEDIAMAC5/Developer/workspace/smi/jsp-rem-001-gipro-patient-app/platforms/android/build.gradle' line: 180

  • What went wrong: A problem occurred evaluating root project 'android'.

    Could not find method versionCode() for arguments [2015042717100] on ProductFlavor_Decorated{name=main, minSdkVersion=null, targetSdkVersion=null, renderscriptTargetApi=null, renderscriptSupportModeEnabled=null, renderscriptNdkModeEnabled=null, versionCode=null, versionName=null, applicationId=null, testApplicationId=null, testInstrumentationRunner=null, testHandleProfiling=null, testFunctionalTest=null, signingConfig=null, resConfig=null, mBuildConfigFields={}, mResValues={}, mProguardFiles=[], mConsumerProguardFiles=[], mManifestPlaceholders={}}.`

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM