簡體   English   中英

Cordova Android應用程序的Gradle版本號更改

[英]Cordova Android App's Version Number Changes in Gradle

我正在嘗試提交我的App,並且版本未按預期發布,請始終在Playstore上附加數字8(結果為30203 8

我已經嘗試刪除並添加相同的Android平台。 從Android Studio的項目結構更改版本似乎也無濟於事。我還應該看什么?

我真的很感謝任何建議,在此先感謝

科爾多瓦:6.0.0

Android平台:4.1.1

<?xml version='1.0' encoding='utf-8'?>
<widget id=.. version="3.2.03" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>Test</name>
    <description>
    ..bla
    </description>
    <author email="a@a.com" href="http://www.web.com">
        Author
    </author>
    <content src="index.html" />
    <access origin="*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="geo:*" />

    <platform name="android">
        <allow-intent href="market:*" />
        <preference name="android-minSdkVersion" value="14" />
        <preference name="android-targetSdkVersion" value ="16" />
        <preference name="Orientation" value="sensorLandscape" />
        <preference name="AndroidPersistentFileLocation" value="Compatibility" />
        <!--<preference name="android-hardwareAccelerated" value="false" />
        <preference name="android-windowSoftInputMode" value="adjustPan" /> -->
    </platform>
</widget>



編輯為了使修復程序在每個版本中運行,我在platform標簽下面的config.xml中創建了一個鈎子:

...
<platform name="android">
        <hook type="before_build" src="scripts/androidVersionFix.js" />
...

在scripts文件夾中,androidVersionFix.js:

#!/usr/bin/env node

/*

----the file creates:-----------
 # In <your-project>/platforms/android/gradle.properties
  cdvVersionCode=30203
---------------------------------
where 30203 is the android-versionCode from config.xml


*/

var configXml = 'config.xml'; 

var fs = require('fs');
var exec = require('child_process').exec;
var appVersion = '';
var fileContents = function() {
    return "#Android version code fix:  In <your-project>/platforms/android/gradle.properties \\n \
cdvVersionCode="+appVersion
};
var command = "sed -n 's/.*android-versionCode=\"\\([^\"]*\\).*/\\1/p' ";


    exec(command + configXml, function(e,out,err){ 
        appVersion = out;
        console.log('echo creating gradle.properties, app Version: ' + appVersion);
        exec('echo "'+fileContents()+'" > ./platforms/android/gradle.properties');
    });

是的,從那里獲取它是build.gradle的問題,不要編輯build.gradle 做一件事在platform / android中創建gradle.properties文件,並將此cdvVersionCode=3.2.03語句粘貼到gradle.properties 它應該工作

這似乎是Cordova 5.0.0及更高版本中未解決的錯誤。 此鏈接具有相同的更多信息 在查看platforms \\ android文件夾下的build.gradle文件之后,以下代碼似乎正在處理版本號,

if (Boolean.valueOf(cdvBuildMultipleApks)) {
        productFlavors {
            armv7 {
                versionCode defaultConfig.versionCode + 2
                ndk {
                    abiFilters "armeabi-v7a", ""
                }
            }
            x86 {
                versionCode defaultConfig.versionCode + 4
                ndk {
                    abiFilters "x86", ""
                }
            }
            all {
                ndk {
                    abiFilters "all", ""
                }
            }
        }
    } else if (!cdvVersionCode) {
      def minSdkVersion = cdvMinSdkVersion ?: privateHelpers.extractIntFromManifest("minSdkVersion")
      // Vary versionCode by the two most common API levels:
      // 14 is ICS, which is the lowest API level for many apps.
      // 20 is Lollipop, which is the lowest API level for the updatable system webview.
      if (minSdkVersion >= 20) {
        defaultConfig.versionCode += 9
      } else if (minSdkVersion >= 14) {
        defaultConfig.versionCode += 8
      }
    }

為了解決該問題,您可以刪除不會造成任何危害的有害代碼build.gradle。

您需要在AndroidManifest.xml而不是config.xml中進行更新。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM