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

时间:2015-04-24 09:32:27

标签: android cordova gradle ionic cordova-cli

my ionic / cordova项目的config.xml文件具有以下设置

机器人-的versionCode = “201504231751”  IOS-CFBundleVersion = “201504231752”

当我尝试使用“cordova build android”构建android时,gradle会抛出一个错误说:

失败:构建因异常而失败。 *地点: 脚本'E:\ Workspaces \ xxx \ xxx \ platforms \ android \ CordovaLib \ cordova.gradle'行:128 * 什么地方出了错: 评估根项目'android'时出现问题。

  

输入字符串:“201504231750”   *尝试:   使用--stacktrace选项运行以获取堆栈跟踪。使用--info或--debug选项运行以获得更多日志输出。

\ CordovaLib \ cordova.gradle上的第128行是ParseInt。我的假设是字符串不能转换为整数,因而也就是问题。

当我将字符串更改为简单整数时,它可以正常工作。

我需要将版本作为时间戳。我该如何克服这个错误?

我在Windows 7机器上。奇怪的是,在mac机器上为android构建了相同的代码库。

由于 smaira

4 个答案:

答案 0 :(得分:5)

我遇到了这个问题并且用一个让我有点不舒服的黑客“解决”了它,但是哪个有效。我注意到错误消息中的字符串附加了一个零(例如,我将versionCode设置为2015073001,但错误消息包含2015073001 0 )。

老实说,我不知道这段代码在做什么(甚至是什么语言),但修改提供的输入对我来说似乎有点奇怪。我修改了从平台/ android / build.gradle的第177行开始的代码:

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

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

答案 1 :(得分:1)

@smaira

我也遇到了同样的错误。

201504231750在java中不是有效的int,它超出了int的范围。

我建议使用unix时间戳代替。我在bash脚本中做了类似下面的操作(在mac上,不知道windows的等价物是什么):

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

答案 2 :(得分:0)

尝试覆盖属性,翻转你自己的闭包

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

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

答案 3 :(得分:0)

@Al Jacinto我确实试图覆盖该属性,但我认为我做得不对。

在cordova.gradle中,

我替换了

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

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

然后我复制了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) }

但是当我尝试构建它时,我得到了同样的错误。但是,当我修改cordova.gradle时,我意识到错误来自build.gradle。所以我打开了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 } }

但这也没有帮助。现在我得到一个不同的错误消息

`*其中: 构建文件'/Users/IOMEDIAMAC5/Developer/workspace/smi/jsp-rem-001-gipro-patient-app/platforms/android/build.gradle'行:180

  • 出了什么问题: 评估根项目'android'时出现问题。

      

    在ProductFlavor_Decorated {name = main,minSdkVersion = null,targetSdkVersion = null,renderscriptTargetApi = null,renderscriptSupportModeEnabled = null,renderscriptNdkModeEnabled = null,versionCode = null,versionName = null,找不到参数[2015042717100]的方法versionCode() applicationId = null,testAppsurmentation = null,testHandleProfiling = null,testFunctionalTest = null,signingConfig = null,resConfig = null,mBuildConfigFields = {},mResValues = {},mProguardFiles = [],mConsumerProguardFiles = [],mManifestPlaceholders = {}}。`

  •   

相关问题