簡體   English   中英

在cordova config.xml中版本號上的gradle拋出錯誤

[英]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

  • 出了什么問題:評估根項目'android'時出現問題。

    無法在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