[英]Gradle throwing error on version numbers in cordova config.xml
my ionic / cordova项目的config.xml文件具有以下设置
android-versionCode =“201504231751”ios-CFBundleVersion =“201504231752”
当我尝试使用“cordova build android”构建for android时,gradle会抛出一个错误说:
FAILURE:构建因异常而失败。 *其中:脚本'E:\\ Workspaces \\ xxx \\ xxx \\ platforms \\ android \\ CordovaLib \\ cordova.gradle'行:128 *出了什么问题:评估根项目'android'时出现问题。
对于输入字符串:“201504231750”*尝试:使用--stacktrace选项运行以获取堆栈跟踪。 使用--info或--debug选项运行以获取更多日志输出。
\\ CordovaLib \\ cordova.gradle上的第128行是ParseInt。 我的假设是字符串不能转换为整数,因此问题。
当我将字符串更改为一个简单的整数时,它可以工作。
我需要版本作为时间戳。 我该如何克服这个错误?
我在Windows 7机器上。 奇怪的是,在mac机器上为android构建了相同的代码库。
谢谢你
我遇到了这个问题并用一个让我有点不舒服的黑客“解决”了它,但是哪个有效。 我注意到错误消息中的字符串附加了一个零(例如,我将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
}
}
@smaira
我也得到了同样的错误。
201504231750在java中不是有效的int,它超出了int的范围。
我建议使用unix时间戳代替。 我在bash脚本中做了类似下面的操作(在mac上,不知道windows的等价物是什么):
timestamp=$(date +%s)
cordova build android -- --gradleArg=-PcdvVersionCode=$timestamp
尝试覆盖属性,翻转你自己的闭包
privateHelpers.extractIntFromManifest = { name -> doExtractIntFromManifest(name) }
同
ext.privateHelpers.extractIntFromManifest = { name -> idontwantyourintversionmethod(name) }
@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
无法在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.