如何在Ionic应用中设置Android构建版本?

xnifntxz  于 2022-12-08  发布在  Ionic
关注(0)|答案(2)|浏览(162)

我有一个爱奥尼亚应用程序(v5/angular),我正在为Android构建它。我试图设置config.xmlwidget属性,如versionandroid-versionCode,但每次构建应用程序时,我的config.xml都会被覆盖。基于大量的谷歌搜索,我认为应该有某种方法来设置我的package.json,以便它在我的config.xml中设置widget属性,但我正在努力找出如何做到这一点。
我的生成脚本是:ng build && npx cap copy
生成的config.xml

<?xml version='1.0' encoding='utf-8'?>
<widget version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
  <access origin="*" />
  
  
</widget>

所需config.xml

<?xml version='1.0' encoding='utf-8'?>
<widget
  version="2.0.0"
  android-versionCode="2"
  xmlns="http://www.w3.org/ns/widgets"
  xmlns:cdv="http://cordova.apache.org/ns/1.0">

  <access origin="*" />

</widget>

我的ionic.config.json

{
  "name": "tutorial",
  "integrations": {
    "capacitor": {}
  },
  "type": "angular"
}

我的capacitor.config.json

{
  "appId": "com.me.app",
  "appName": "Tutorial",
  "bundledWebRuntime": false,
  "npmClient": "npm",
  "webDir": "www",
  "plugins": {
    "SplashScreen": {
      "launchShowDuration": 0
    }
  },
  "cordova": {}
}

我的package.json

{
  "name": "tutorial",
  "version": "0.0.1",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "build-mobile": "ng build && npx cap copy",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular-devkit/build-angular": "^0.803.24",
    "@angular/common": "~8.2.14",
    "@angular/core": "~8.2.14",
    "@angular/forms": "~8.2.14",
    "@angular/platform-browser": "~8.2.14",
    "@angular/platform-browser-dynamic": "~8.2.14",
    "@angular/router": "~8.2.14",
    "@capacitor/android": "^2.4.0",
    "@capacitor/core": "2.4.0",
    "@capacitor/ios": "^2.4.0",
    "@ionic-native/core": "^5.0.0",
    "@ionic-native/geolocation": "^5.23.0",
    "@ionic-native/splash-screen": "^5.0.0",
    "@ionic-native/status-bar": "^5.0.0",
    "@ionic/angular": "^5.0.0",
    "@ionic/storage": "2.2.0",
    "@microsoft/applicationinsights-web": "^2.5.6",
    "@okta/okta-auth-js": "^3.0.0",
    "@types/lodash": "^4.14.149",
    "angular-oauth2-oidc": "^9.0.1",
    "core-js": "^2.5.4",
    "lodash": "^4.17.15",
    "rxjs": "~6.5.1",
    "tslib": "^1.9.0",
    "zone.js": "~0.9.1"
  },
  "devDependencies": {
    "@angular/cli": "~8.3.23",
    "@angular/compiler": "~8.2.14",
    "@angular/compiler-cli": "~8.2.14",
    "@angular/language-service": "~8.2.14",
    "@capacitor/cli": "2.4.0",
    "@ionic/angular-toolkit": "^2.1.1",
    "@types/node": "~8.9.4",
    "ts-node": "~7.0.0",
    "tslint": "~5.15.0",
    "typescript": "~3.4.3"
  },
  "description": "An Ionic project"
}
3df52oht

3df52oht1#

据我所知,生成的config.xml实际上并没有用于Capacitor构建,版本和构建编号实际上是在build.gradle中设置的:

apply plugin: 'com.android.application'

android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    defaultConfig {
        applicationId "com.me.app"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 2
        versionName "2.0.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

...
nimxete2

nimxete22#

我会提供一些新的信息来帮助类似的场景。最新的VS Code Ionic扩展有一个选项可以轻松地更新应用程序的版本。一旦你使用它,它会自动更新iOS和Android的一些位置。

相关问题