Gradle error when releasing version number in cordova config.xml

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

Android-VersionCode = "201504231751" KCH-CFBundleVersion = "201504231752"

When I try to build android using "corova build android" gradle throws an error:

FAILURE: Build failed with exception. * Where: Script 'E: \ Workspaces \ xxx \ xxx \ platform \ android \ CordovaLib \ cordova.gradle' line: 128 * What went wrong: There was a problem evaluating the "android" of the root project.

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

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

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

I need a time stamp version. How to overcome this error?

I'm on a windows 7 machine. It's weird that the same codebase is generated for android on a mac machine.

Thanks smaira

+3


source to share


4 answers


I ran into this problem and "solved" it with a hack, which makes me a little awkward, but that works. I noticed that the line in the error message has a null appended to the end (for example, I set the version code 2015073001, but the error message contains 2015073001 0 ).

To be honest, I don't know what this code does (or even what language), but it seems a little strange to me to change the input provided. I changed the code starting at line 177 platforms /android/build.gradle:

    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
        }
    }

      

+5


source


@smaira

I was getting the same error too.

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



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

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

      

+1


source


Try to override the property, flop your own clos

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

      

from

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

      

0


source


@Al Jacinto I tried to override the property but I think I am not doing it right.

In cordova.gradle,

I replaced

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

from

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

Then I duplicated the extractIntFromManifest method, renamed dontExtractIntFromManifest and removed parseInt from the return value 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 to build it i got the same error. However, I figured out that the error was coming from build.gradle while I was changing cordova.gradle. So I opened build.gradle and changed 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 am getting another error message which is

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

  • What went wrong: There was a problem evaluating the "android" of the root project.

    Could not find versionCode () method for arguments [2015042717100] on ProductFlavor_Decorated {name = main, minSdkVersion = null, targetSdkVersion = null, renderscriptTargetApi = null, renderscriptSupportModeEnabled = null, renderscriptNdkModeEnabled = null, renderscriptNdkModeEnabled = null, renderscriptNdkModeEnabled = null, renderscriptNdkModeEnabled = null , testApplicationId = null, testInstrumentationRunner = null, testHandleProfiling = null, testFunctionalTest = null, signedConfig = null, resConfig = null, mBuildConfigFields = {}, mResValues โ€‹โ€‹= {}, mProguardFiles = [], mResValues โ€‹โ€‹= {}, mProguardFiles = [], mResValues โ€‹โ€‹= {}, mProguardFiles = [], mConsumerProestguardFiles = [], mConsumerProestguardFiles = [] }}. `

0


source







All Articles