Ionic - APK 构建总是生成具有旧值的旧 apk

Ionic - APK Build always produces old apk with old values

我目前正在使用 Capacitor 开发 Ionic 应用程序。奇怪的是,apk 产生了意想不到的结果。

这种情况经常发生。让我描述一下我的工作。

构建 apk 时,我首先确保删除 capacitor.config.json 中的 server 键。当我使用 Ionic Live Reload 时,它写在那里。

然后我使用以下命令构建 apk:

  1. ionic build

  2. ionic cap copy

  3. ionic cap sync

  4. ionic cap open android

在我点击“播放”按钮在我的设备上安装该应用程序之前,我转到我的设置并清除该应用程序的缓存和数据,然后卸载该应用程序。

然后我在 phone 上安装新的应用程序。但奇怪的是,有旧值,还有一些来自内部数据库的旧值。

怎么会这样?我做错了什么?

这是我的 package.json:

{
  "name": "OrgAtwork_mobile",
  "version": "0.08.06",
  "author": "Ionic Framework",
  "homepage": "https://ionicframework.com/",
  "scripts": {
    "ng": "ng",
    "start": "ng serve --proxy-config proxy.conf.json",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/cdk": "^10.2.0",
    "@angular/common": "^10.0.14",
    "@angular/core": "^10.0.14",
    "@angular/flex-layout": "^10.0.0-beta.32",
    "@angular/forms": "^10.0.14",
    "@angular/platform-browser": "^10.0.14",
    "@angular/platform-browser-dynamic": "^10.0.14",
    "@angular/router": "^10.0.14",
    "@capacitor/android": "^2.4.1",
    "@capacitor/core": "^2.4.0",
    "@capacitor/ios": "^2.4.0",
    "@ionic-native/core": "^5.28.0",
    "@ionic-native/http": "^5.29.0",
    "@ionic-native/launch-navigator": "^5.28.0",
    "@ionic-native/native-storage": "^5.28.0",
    "@ionic-native/screen-orientation": "^5.28.0",
    "@ionic-native/splash-screen": "^5.28.0",
    "@ionic-native/sqlite": "^5.28.0",
    "@ionic-native/status-bar": "^5.28.0",
    "@ionic/angular": "^5.3.2",
    "@types/hammerjs": "^2.0.36",
    "@types/underscore": "^1.10.24",
    "add": "^2.0.6",
    "cordova-plugin-actionsheet": "^2.3.3",
    "cordova-plugin-advanced-http": "^3.1.0",
    "cordova-plugin-app-preferences": "^0.99.3",
    "cordova-plugin-dialogs": "^2.0.2",
    "cordova-plugin-file": "^6.0.2",
    "cordova-plugin-geolocation": "^4.0.2",
    "cordova-plugin-nativestorage": "^2.3.2",
    "cordova-plugin-screen-orientation": "^3.0.2",
    "cordova-sqlite-storage": "^5.0.1",
    "es6-promise-plugin": "^4.2.2",
    "hammerjs": "^2.0.8",
    "ionic-long-press": "^2.0.3",
    "js-sha256": "^0.9.0",
    "moment": "^2.27.0",
    "moment-range": "^4.0.2",
    "rxjs": "^6.6.3",
    "rxjs-compat": "^6.6.3",
    "sha.js": "^2.4.11",
    "tslib": "^2.0.1",
    "uk.co.workingedge.phonegap.plugin.launchnavigator": "^5.0.4",
    "underscore": "^1.11.0",
    "zone.js": "~0.10.3"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^0.1100.2",
    "@angular/cli": "^10.0.8",
    "@angular/compiler": "^10.0.14",
    "@angular/compiler-cli": "^10.0.14",
    "@angular/language-service": "^10.0.14",
    "@capacitor/cli": "2.3.0",
    "@ionic/angular-toolkit": "^2.3.3",
    "@types/jasmine": "^3.5.14",
    "@types/jasminewd2": "~2.0.8",
    "@types/node": "^14.6.4",
    "@types/uuid": "^8.3.0",
    "codelyzer": "^6.0.0",
    "cordova-plugin-ionic-keyboard": "^2.2.0",
    "cordova-plugin-ionic-webview": "^4.2.1",
    "cordova-plugin-splashscreen": "^5.0.2",
    "cordova-plugin-statusbar": "^2.4.2",
    "cordova-plugin-whitelist": "^1.3.3",
    "jasmine-core": "~3.5.0",
    "jasmine-spec-reporter": "~5.0.2",
    "karma": "^5.1.1",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage-istanbul-reporter": "~3.0.3",
    "karma-jasmine": "~3.3.1",
    "karma-jasmine-html-reporter": "^1.5.4",
    "protractor": "~7.0.0",
    "ts-node": "~8.10.2",
    "tslint": "^6.1.3",
    "typescript": "~3.9.7"
  },
  "description": "An Ionic project",
  "cordova": {
    "plugins": {
      "cordova-plugin-whitelist": {},
      "cordova-plugin-statusbar": {},
      "cordova-plugin-splashscreen": {},
      "cordova-plugin-ionic-webview": {},
      "cordova-plugin-ionic-keyboard": {}
    },
    "platforms": []
  }
}

我发现了问题。

在Android清单中,设置android:allowBackup="false"。它默认为 true,当它不设置为 false 时将加载一些旧数据。

我遇到了同样的问题。我通过删除 ionic 应用程序中的 androiddist 文件夹解决了这个问题。然后我运行:

npm run build
ionic capacitor add android
ionic capacitor open android’

更新: 您也可以在不删除文件夹的情况下执行以下步骤:

npm run build
npx cap sync
ionic capacitor open android
(In android studio) sync project with gradle files