我正在使用 Ionic Angular 和 Capacitor 构建一个应用程序。 根据 Capacitor 的文档,他们从 5.0 版本开始支持 Android:
Android 版本对 Capacitor 的支持比 iOS 更复杂。目前,我们的目标是 API 级别 21 或更高版本,即 Android 5.0 (Lollipop) 或更高版本。这代表了超过 90% 的 Android 市场。
但是当我尝试在真实设备上启动 Android 6.0.1 Marshmallow 中的应用程序(而不是我知道使用非常旧的 WebView 的模拟器)时,我从 Logcat 收到此错误:
2023-02-07 20:17:30.316 1291-1291/com.my.app E/ApkAssets:错误 加载资产 asset/natives_blob_64.bin: java.io.FileNotFoundException:资产/natives_blob_64.bin
2023-02-07 20:17:30.316 1291-1291/com.my.app E/ApkAssets:错误 加载资产assets/snapshot_blob_64.bin: java.io.FileNotFoundException:资产/snapshot_blob_64.bin
2023-02-07 20:17:33.179 1291-1291/com.my.app E/电容器:系统 不支持WebView
2023-02-07 20:17:33.300 1291-1381/com.my.app E/libEGL: validate_display:255错误3008(EGL_BAD_DISPLAY)
2023-02-07 20:17:33.546 1291-1291/com.my.app E/电容器/控制台: 文件:http://localhost/ - 第 80 行 - 消息:未捕获的语法错误: 意外的令牌 (
我已经尝试使用多个 browserslistrc 配置并将 tsconfig.ts 中的目标设置为 es2015,但没有任何效果。
这是我的package.json:
{
"name": "my-app",
"version": "0.0.3",
"author": "John Smith",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"android": "ionic capacitor sync && ionic capacitor open android",
"ios": "ionic capacitor sync && ionic capacitor open ios",
"androidProd": "ionic capacitor sync && ionic capacitor build android --prod",
"iosProd": "ionic capacitor sync && ionic capacitor build ios --prod",
"buildProd": "ionic capacitor sync && ionic build --prod"
},
"browserslist": [
"defaults and supports es6-module",
"maintained node versions"
],
"private": true,
"dependencies": {
"@angular/common": "^15.0.2",
"@angular/core": "^15.0.2",
"@angular/forms": "^15.0.2",
"@angular/material": "^15.0.1",
"@angular/platform-browser": "^15.0.2",
"@angular/platform-browser-dynamic": "^15.0.2",
"@angular/router": "^15.0.2",
"@auth0/angular-jwt": "^5.1.0",
"@awesome-cordova-plugins/camera": "^6.3.0",
"@awesome-cordova-plugins/core": "^6.3.0",
"@awesome-cordova-plugins/device": "^6.3.0",
"@awesome-cordova-plugins/diagnostic": "^6.3.0",
"@awesome-cordova-plugins/geolocation": "^6.3.0",
"@awesome-cordova-plugins/local-notifications": "^6.3.0",
"@awesome-cordova-plugins/power-optimization": "^6.3.0",
"@awesome-cordova-plugins/screen-orientation": "^6.3.0",
"@awesome-cordova-plugins/social-sharing": "^6.3.0",
"@capacitor-community/facebook-login": "^4.0.0",
"@capacitor/android": "^4.6.1",
"@capacitor/app": "^4.1.1",
"@capacitor/browser": "^4.1.0",
"@capacitor/core": "^4.6.1",
"@capacitor/ios": "4.6.1",
"@capacitor/keyboard": "^4.1.0",
"@capacitor/push-notifications": "^4.1.2",
"@capacitor/status-bar": "^4.1.1",
"@ionic/angular": "^6.3.9",
"@ionic/pwa-elements": "^3.1.1",
"@ngx-translate/core": "^14.0.0",
"@ngx-translate/http-loader": "^7.0.0",
"cordova-plugin-badge": "^0.8.8",
"cordova-plugin-camera": "^6.0.0",
"cordova-plugin-device": "^2.1.0",
"cordova-plugin-geolocation": "^4.1.0",
"cordova-plugin-local-notification": "^0.9.0-beta.2",
"cordova-plugin-power-optimization": "^0.0.4",
"cordova-plugin-screen-orientation": "^3.0.2",
"cordova-plugin-x-socialsharing": "^6.0.4",
"cordova-support-android-plugin": "^2.0.4",
"cordova.plugins.diagnostic": "^7.1.1",
"crypto-js": "^4.1.1",
"es6-promise-plugin": "^4.2.2",
"jetifier": "^2.0.0",
"luxon": "^3.1.1",
"net": "^1.0.2",
"rxjs": "~7.6.0",
"sockjs-client": "^1.6.1",
"stompjs": "^2.3.3",
"swiper": "^8.4.5",
"tslib": "^2.4.1",
"uuid": "^9.0.0",
"zone.js": "~0.12.0"
},
"devDependencies": {
"@angular-devkit/build-angular": "^15.0.2",
"@angular-eslint/builder": "~15.1.0",
"@angular-eslint/eslint-plugin": "~15.1.0",
"@angular-eslint/eslint-plugin-template": "~15.1.0",
"@angular-eslint/template-parser": "~15.1.0",
"@angular/cli": "^15.0.2",
"@angular/compiler": "^15.0.2",
"@angular/compiler-cli": "^15.0.2",
"@angular/language-service": "^15.0.2",
"@capacitor/cli": "^4.6.1",
"@ionic/angular-toolkit": "^7.0.0",
"@types/jasmine": "~4.3.1",
"@types/jasminewd2": "~2.0.10",
"@types/node": "^18.11.11",
"@typescript-eslint/eslint-plugin": "5.45.1",
"@typescript-eslint/parser": "5.45.1",
"eslint": "^8.29.0",
"eslint-plugin-import": "2.26.0",
"eslint-plugin-jsdoc": "39.6.4",
"eslint-plugin-prefer-arrow": "1.2.3",
"jasmine-core": "~4.5.0",
"jasmine-spec-reporter": "~7.0.0",
"karma": "~6.4.1",
"karma-chrome-launcher": "~3.1.1",
"karma-coverage": "~2.2.0",
"karma-coverage-istanbul-reporter": "~3.0.3",
"karma-jasmine": "~5.1.0",
"karma-jasmine-html-reporter": "^2.0.0",
"protractor": "~7.0.0",
"ts-node": "~10.9.1",
"typescript": "~4.8.2"
},
"description": "An absolute awesome app"
}
这是我的 tsconfig.ts:
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"importHelpers": true,
"target": "es2015",
"module": "es2020",
"lib": [
"es2018",
"dom"
],
"useDefineForClassFields": false,
"allowSyntheticDefaultImports": true
},
"angularCompilerOptions": {
"enableI18nLegacyMessageIdFormat": false,
"strictInjectionParameters": true,
"strictInputAccessModifiers": true,
"strictTemplates": true,
"allowSyntheticDefaultImports": true
}
}
我真的需要在 Android 6 上运行这个应用程序,因为这个应用程序需要经过 Meta 的审核过程才能使用一些 Facebook/Instagram 数据,并且他们正在 Android 6 Marshmallow 设备上进行测试,但只要出现此错误,应用程序将显示启动画面,然后只显示白屏。
我在不同旧 Android 版本的模拟器中遇到了这个问题。解决方案是通过 Google Play 更新 Chrome 和 System Webview,以使应用程序再次正常启动。项目方面我不需要做任何改变。