我繼承了一個帶有 Angular 和 Cordova 的 Ionic 5 專案,而不是 Capacitor。它使用了幾個原生插件,即 QR Scanner 和 In-app Browser。該應用程式在 Android 模擬器中啟動時運行良好,使用:
ionic cordova run android
現在我想構建一個 APK,我可以將它分發給幾個測驗人員來試用該應用程式。必須使用特定配置構建此 APK 以連接到預生產環境(使用 Firebase,但我猜這無關緊要)。我正在使用的程序是:
ionic build --prod --platform=android --configuration=preprod
ionic cordova prepare android --no-build --prod
ionic cordova build android --no-build --release
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore <PATH_TO_KS> <PATH_TO_APK> <KEY_NAME>
zipalign -v 4 <PATH_TO_APK> <PATH_TO_SIGNED_APK>
現在簽名的 APK 正確安裝到模擬器,應用程式啟動并連接到預生產環境。但本機插件(例如 QR 掃描儀)不起作用。我得到的錯誤是Native:嘗試呼叫 QRScanner.prepare,但 Cordova 不可用。確保包含 cordova.js 或在 device/simulator 中運行。Cordova 似乎沒有激活,因為在列印平臺時,它們不包含"cordova"字串:
import { Platform } from '@ionic/angular';
constructor(private platform: Platform) {...}
ngOnInit() {
this.platforms = this.platform.platforms().join(',');
}
運行時的結果this.platforms是android,phablet,cordova,desktop,hybrid ,但在安裝我使用上述程序構建的 APK 時ionic cordova run android只是android,phablet,desktop 。
Do you have any ideas why? I am quite new to mobile development, so you can absolutely assume I have made newbie mistakes. And if you feel that any other information would be useful, please let me know and I will happily add it.
EDIT: In order to support the preprod configuration, I added the following sections in angular.json:
{
"projects": {
"app": {
"architect": {
"build": {
"configurations": {
"preprod": {
...
}}}}}}}
Building with just ionic cordova build android yields the following error:
> ng run app:ionic-cordova-build:preprod --platform=android
An unhandled exception occurred: Configuration 'preprod' is not set in the workspace.
This is why I am building in 3 phases, ionic build ... --configuration=preprod, ionic cordova prepare ..., ionic cordova build android --no-build. My intention is for the first to build the app in the correct configuration, the second to update the Android project with the web files built with the configuration and the third to build the final APK.
uj5u.com熱心網友回復:
為除錯(apk)構建新應用程式的簡單常規方法只是呼叫
ionic cordova build android
這個呼叫在內部準備,所以不需要另一個呼叫。它將生成一個 apk 檔案,您可以使用該檔案在設備上進行測驗(可能還有模擬器,具體取決于功能)。
到了要發布到商店的時候,考慮到這是一個新應用并且 Google 的要求發生了變化,您需要構建一個.aab檔案。以下將做到這一點:
ionic cordova build android --release
至于簽名,您需要向 Google 提供密鑰,他們將通過提供的 .aab 為您簽名。這里有更詳細的解釋:
https://ionicframework.com/blog/google-play-android-app-bundle-requirement-for-new-apps/
現在,如果您需要創建自定義配置(您所指的preprod),因為您有一些非常具體的角度環境更改或要求,超出了默認值必須提供的功能,正如您在評論中發現的那樣,您將需要編輯angular.json檔案以添加它。
Ionic 默認為環境變數提供了一個結構體,可以在src/environments. 可以在此處找到有關其作業原理的更多詳細資訊:
https://medium.com/swlh/environment-variables-in-angular-ionic-8aa1698f2cc5
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/433935.html
標籤:android cordova ionic-framework
上一篇:Excel計數兩個日期之間的唯一ID 每個ID的另一列的不同計數
下一篇:判斷請求是否來自移動應用
