简体   繁体   English

在cordova config.xml中版本号上的gradle抛出错误

[英]Gradle throwing error on version numbers in cordova config.xml

The config.xml file of my ionic/cordova project has the following set my ionic / cordova项目的config.xml文件具有以下设置

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

When I try building for android using "cordova build android" gradle throws me an error saying : 当我尝试使用“cordova build android”构建for android时,gradle会抛出一个错误说:

FAILURE: Build failed with an exception. FAILURE:构建因异常而失败。 * Where: Script 'E:\\Workspaces\\xxx\\xxx\\platforms\\android\\CordovaLib\\cordova.gradle' line: 128 * What went wrong: A problem occurred evaluating root project 'android'. *其中:脚本'E:\\ Workspaces \\ xxx \\ xxx \\ platforms \\ android \\ CordovaLib \\ cordova.gradle'行:128 *出了什么问题:评估根项目'android'时出现问题。

For input string: "201504231750" * Try: Run with --stacktrace option to get the stack trace. 对于输入字符串:“201504231750”*尝试:使用--stacktrace选项运行以获取堆栈跟踪。 Run with --info or --debug option to get more log output. 使用--info或--debug选项运行以获取更多日志输出。

Line 128 on \\CordovaLib\\cordova.gradle is a ParseInt. \\ CordovaLib \\ cordova.gradle上的第128行是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. 我在Windows 7机器上。 What's strange is that the same code base gets built for android on a mac machine. 奇怪的是,在mac机器上为android构建了相同的代码库。

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 ). 我注意到错误消息中的字符串附加了一个零(例如,我将versionCode设置为2015073001,但错误消息包含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: 我修改了从平台/ android / build.gradle的第177行开始的代码:

    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 @smaira

I was getting the same error as well. 我也得到了同样的错误。

201504231750 is not a valid int in java, it exceeds the bounds of an int. 201504231750在java中不是有效的int,它超出了int的范围。

I would recommend using a unix timestamp instead. 我建议使用unix时间戳代替。 I'm doing something similar to the following in my bash script (on a mac, don't know what the windows equivalent is): 我在bash脚本中做了类似下面的操作(在mac上,不知道windows的等价物是什么):

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. @Al Jacinto我确实尝试过覆盖该属性,但我认为我做错了。

In cordova.gradle , 在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 然后我复制了extractIntFromManifest方法,重命名为dontExtractIntFromManifest并从返回中删除了parseInt,如下所示

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. 但是,当我修改cordova.gradle时,我意识到错误来自build.gradle。 So I opened build.gradle and changed the defaultConfig 所以我打开了build.gradle并更改了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 `*其中:构建文件'/Users/IOMEDIAMAC5/Developer/workspace/smi/jsp-rem-001-gipro-patient-app/platforms/android/build.gradle'行:180

  • What went wrong: A problem occurred evaluating root project 'android'. 出了什么问题:评估根项目'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={}}.` 无法在ProductFlavor_Decorated上找到参数[2015042717100]的方法versionCode(){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 = {}} .`

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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