使用“-prod”构建运行时,Ionic 应用程序在启动画面处停止
Posted
技术标签:
【中文标题】使用“-prod”构建运行时,Ionic 应用程序在启动画面处停止【英文标题】:Ionic app halts at splash screen when running with ‘–prod’ build 【发布时间】:2018-08-19 09:42:56 【问题描述】:我一直在开发一个包含“应用内购买”、“firebase 动态链接”等的应用。当我使用命令运行该应用时,该应用在 android 和 ios 上都能正常运行:
ionic cordova run android
ionic cordova build ios
但是,一旦我在他们面前使用“--prod”运行应用程序,该应用程序就会卡在我的启动屏幕/app.component.ts 屏幕上。
我的一些应用程序的结构如下所示:
config.xml
<?xml version='1.0' encoding='utf-8'?>
<widget id="io.ionic.wordforyou" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>WordForYou</name>
<description>An awesome Ionic/Cordova app.</description>
<author email="hi@ionicframework" href="http://ionicframework.com/">Ionic Framework Team</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:*" />
<preference name="ScrollEnabled" value="false" />
<preference name="android-minSdkVersion" value="16" />
<preference name="BackupWebStorage" value="none" />
<preference name="SplashMaintainAspectRatio" value="true" />
<preference name="FadeSplashScreenDuration" value="300" />
<preference name="SplashShowOnlyFirstTime" value="false" />
<preference name="SplashScreen" value="screen" />
<preference name="loadUrlTimeoutValue" value="70000" />
<preference name="webviewbounce" value="false" />
<preference name="UIWebViewBounce" value="false" />
<preference name="DisallowOverscroll" value="true" />
<preference name="SplashScreenDelay" value="3000" />
<platform name="android">
<preference name="GoogleAndroidClientId" value="some_id_here" />
<resource-file src="google-services.json" target="google-services.json" />
<allow-intent href="market:*" />
<icon density="ldpi" src="resources/android/icon/drawable-ldpi-icon.png" />
<icon density="mdpi" src="resources/android/icon/drawable-mdpi-icon.png" />
<icon density="hdpi" src="resources/android/icon/drawable-hdpi-icon.png" />
<icon density="xhdpi" src="resources/android/icon/drawable-xhdpi-icon.png" />
<icon density="xxhdpi" src="resources/android/icon/drawable-xxhdpi-icon.png" />
<icon density="xxxhdpi" src="resources/android/icon/drawable-xxxhdpi-icon.png" />
<splash density="land-ldpi" src="resources/android/splash/drawable-land-ldpi-screen.png" />
<splash density="land-mdpi" src="resources/android/splash/drawable-land-mdpi-screen.png" />
<splash density="land-hdpi" src="resources/android/splash/drawable-land-hdpi-screen.png" />
<splash density="land-xhdpi" src="resources/android/splash/drawable-land-xhdpi-screen.png" />
<splash density="land-xxhdpi" src="resources/android/splash/drawable-land-xxhdpi-screen.png" />
<splash density="land-xxxhdpi" src="resources/android/splash/drawable-land-xxxhdpi-screen.png" />
<splash density="port-ldpi" src="resources/android/splash/drawable-port-ldpi-screen.png" />
<splash density="port-mdpi" src="resources/android/splash/drawable-port-mdpi-screen.png" />
<splash density="port-hdpi" src="resources/android/splash/drawable-port-hdpi-screen.png" />
<splash density="port-xhdpi" src="resources/android/splash/drawable-port-xhdpi-screen.png" />
<splash density="port-xxhdpi" src="resources/android/splash/drawable-port-xxhdpi-screen.png" />
<splash density="port-xxxhdpi" src="resources/android/splash/drawable-port-xxxhdpi-screen.png" />
</platform>
<platform name="ios">
<preference name="GoogleIOSClientId" value="some_id_here" />
<resource-file src="GoogleService-Info.plist" />
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
<icon src="resources/ios/icon/icon.png" />
<icon src="resources/ios/icon/icon@2x.png" />
<icon src="resources/ios/icon/icon-40.png" />
<icon src="resources/ios/icon/icon-40@2x.png" />
<icon src="resources/ios/icon/icon-40@3x.png" />
<icon src="resources/ios/icon/icon-50.png" />
<icon src="resources/ios/icon/icon-50@2x.png" />
<icon src="resources/ios/icon/icon-60.png" />
<icon src="resources/ios/icon/icon-60@2x.png" />
<icon src="resources/ios/icon/icon-60@3x.png" />
<icon src="resources/ios/icon/icon-72.png" />
<icon src="resources/ios/icon/icon-72@2x.png" />
<icon src="resources/ios/icon/icon-76.png" />
<icon src="resources/ios/icon/icon-76@2x.png" />
<icon src="resources/ios/icon/icon-83.5@2x.png" />
<icon src="resources/ios/icon/icon-small.png" />
<icon src="resources/ios/icon/icon-small@2x.png" />
<icon src="resources/ios/icon/icon-small@3x.png" />
<icon src="resources/ios/icon/icon-1024.png" />
<splash src="resources/ios/splash/Default-568h@2x~iphone.png" />
<splash src="resources/ios/splash/Default-667h.png" />
<splash src="resources/ios/splash/Default-736h.png" />
<splash src="resources/ios/splash/Default-Landscape-736h.png" />
<splash src="resources/ios/splash/Default-Landscape@2x~ipad.png" />
<splash src="resources/ios/splash/Default-Landscape@~ipadpro.png" />
<splash src="resources/ios/splash/Default-Landscape~ipad.png" />
<splash src="resources/ios/splash/Default-Portrait@2x~ipad.png" />
<splash src="resources/ios/splash/Default-Portrait@~ipadpro.png" />
<splash src="resources/ios/splash/Default-Portrait~ipad.png" />
<splash src="resources/ios/splash/Default@2x~iphone.png" />
<splash src="resources/ios/splash/Default~iphone.png" />
<splash src="resources/ios/splash/Default@2x~universal~anyany.png" />
</platform>
<allow-navigation href="http://192.168.0.181:8100" />
<allow-navigation href="http://192.168.1.133:8100" />
<allow-navigation href="http://192.168.0.180:8100" />
<engine name="ios" spec="~4.5.4" />
<engine name="android" spec="~6.3.0" />
<plugin name="cordova-sqlite-storage" spec="^2.2.1" />
<plugin name="ionic-plugin-keyboard" spec="^2.2.1" />
<plugin name="cordova-plugin-whitelist" spec="^1.3.1" />
<plugin name="cordova-plugin-device" spec="^1.1.4" />
<plugin name="cordova-plugin-splashscreen" spec="^4.0.3" />
<plugin name="cordova-plugin-ionic-webview" spec="^1.1.16" />
<plugin name="cc.fovea.cordova.purchase" spec="^7.1.2">
<variable name="BILLING_KEY" value="some_key_here" />
</plugin>
<plugin name="cordova-support-google-services" spec="^1.0.0" />
<plugin name="cordova-plugin-firebase-dynamiclinks" spec="^0.12.1">
<variable name="APP_DOMAIN" value="waa24.app.goo.gl" />
<variable name="APP_PATH" value="/" />
<variable name="FIREBASE_VERSION" value="11.0.+" />
</plugin>
<plugin name="cordova-plugin-x-socialsharing" spec="^5.3.2" />
</widget>
app.component.ts
@Component(
templateUrl: 'app.html',
providers: [
InAppPurchase2,
HomeService,
AuthService,
]
)
export class MyApp
@ViewChild(Nav) nav: Nav;
rootPage: any;
showStartupScreen: Boolean = true;
public tempRootPage: any;
public hasFirebaseDynamicLink: Boolean = false;
constructor(
private platform: Platform,
statusBar: StatusBar,
splashScreen: SplashScreen,
private store: InAppPurchase2,
// private deeplinks: Deeplinks,
private authService: AuthService,
private homeService: HomeService,
private singletonService: SingletonService,
private storage: Storage,
private events: Events,
private toast: Toast,
private firebaseDynamicLinks: FirebaseDynamicLinks,
)
platform.ready().then(() =>
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
statusBar.styleDefault();
splashScreen.hide();
this._initIap();
// this._initDeeplinks();
this._handleEvents();
this._initServerCalls();
);
...
在 ios 中,我正在获取日志:
2018-03-11 09:41:33.332179+0530 WordForYou[1159:183502] DiskCookieStorage changing policy from 2 to 0, cookie file: file:///private/var/mobile/Containers/Data/Application/C577545E-13A7-4C2F-86D7-F3D3D2A74A2E/Library/Cookies/Cookies.binarycookies
2018-03-11 09:41:33.428318+0530 WordForYou[1159:183502] Apache Cordova native platform version 4.5.3 is starting.
2018-03-11 09:41:33.430405+0530 WordForYou[1159:183502] Multi-tasking -> Device: YES, App: YES
2018-03-11 09:41:33.473991+0530 WordForYou[1159:183502] CDVWKWebViewEngine: trying to inject XHR polyfill
2018-03-11 09:41:33.847546+0530 WordForYou[1159:183502] CDVWKWebViewEngine will reload WKWebView if required on resume
2018-03-11 09:41:33.847717+0530 WordForYou[1159:183502] Using Ionic WKWebView
2018-03-11 09:41:33.849899+0530 WordForYou[1159:183502] [CDVTimer][console] 0.231028ms
2018-03-11 09:41:33.850581+0530 WordForYou[1159:183502] [CDVTimer][handleopenurl] 0.357032ms
2018-03-11 09:41:33.856422+0530 WordForYou[1159:183502] [CDVTimer][intentandnavigationfilter] 5.723953ms
2018-03-11 09:41:33.856731+0530 WordForYou[1159:183502] [CDVTimer][gesturehandler] 0.190973ms
2018-03-11 09:41:33.871924+0530 WordForYou[1159:183502] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /private/var/containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles
2018-03-11 09:41:33.872972+0530 WordForYou[1159:183502] [MC] Reading from public effective user settings.
2018-03-11 09:41:33.877654+0530 WordForYou[1159:183502] InAppPurchase[objc] Initialized.
2018-03-11 09:41:33.877766+0530 WordForYou[1159:183502] [CDVTimer][inapppurchase] 20.957947ms
2018-03-11 09:41:33.901254+0530 WordForYou[1159:183502] [CDVTimer][splashscreen] 23.403049ms
2018-03-11 09:41:33.903321+0530 WordForYou[1159:183502] [CDVTimer][keyboard] 1.774073ms
2018-03-11 09:41:33.903649+0530 WordForYou[1159:183502] Starting Firebase DynamicLinks plugin
2018-03-11 09:41:33.903767+0530 WordForYou[1159:183502] [CDVTimer][firebasedynamiclinks] 0.256062ms
2018-03-11 09:41:33.904093+0530 WordForYou[1159:183502] [CDVTimer][socialsharing] 0.259042ms
2018-03-11 09:41:33.904176+0530 WordForYou[1159:183502] [CDVTimer][TotalPluginStartup] 55.562019ms
2018-03-11 09:41:33.911672+0530 WordForYou[1159:183545] [MC] Filtering mail sheet accounts for bundle ID: io.ionic.wordforyou, source account management: 1
2018-03-11 09:41:33.922380+0530 WordForYou[1159:183545] [MC] Result: YES
2018-03-11 09:41:33.922951+0530 WordForYou[1159:183545] [MC] Filtering mail sheet accounts for bundle ID: io.ionic.wordforyou, source account management: 1
2018-03-11 09:41:33.924259+0530 WordForYou[1159:183545] [MC] Result: YES
2018-03-11 09:41:34.335772+0530 WordForYou[1159:183502] InAppPurchase[objc] (before init): WARNING: Your app should be single page to use in-app-purchases. onReset is not supported.
我的ionic info
打印了这个:
cli packages: (/usr/local/lib/node_modules)
@ionic/cli-utils : 1.19.0
ionic (Ionic CLI) : 3.19.0
global packages:
cordova (Cordova CLI) : 7.1.0
local packages:
@ionic/app-scripts : 3.1.5
Cordova Platforms : android 6.3.0 ios 4.5.4
Ionic Framework : ionic-angular 3.9.2
System:
ios-deploy : 1.9.2
Node : v6.11.3
npm : 3.10.10
OS : macOS High Sierra
Xcode : Xcode 9.2 Build version 9C40b
Environment Variables:
ANDROID_HOME : not set
Misc:
backend : pro
我的 chrome 检查器向我显示了此日志(仅在开发模式下,顺便说一下我的应用正在处理此日志 - 这仅供您参考)
我应该如何进行?
【问题讨论】:
【参考方案1】:你想在什么安卓版本上运行它? 我问这个是因为 Ionic 3 不支持所有 android 版本。根据我的经验,4.4 及更高版本可以运行良好,但较低版本有这种问题。
另外,在开始执行 --prod 和 --release 之前清理(删除文件)在 platform/android/app/build/outputs/apk/release 和 platform/android/app/build/outputs/apk/debug 下
比运行你的 --prod 或 --release
【讨论】:
我在 Android 6.0 版上运行它,我已经完成了您提到的所有操作,但我的应用程序仍然无法在这两个平台上运行。感谢回复 你可以尝试将这个:<preference name="SplashScreenDelay" value="2000"/> <preference name="FadeSplashScreenDuration" value="2000"/> <preference name="SplashScreen" value="screen"/> <preference name="ShowSplashScreenSpinner" value="false"/> <preference name="AutoHideSplashScreen" value="false" />
添加到你的 config.xml以上是关于使用“-prod”构建运行时,Ionic 应用程序在启动画面处停止的主要内容,如果未能解决你的问题,请参考以下文章
Ionic 3 - 应用程序在使用 --prod 构建后显示空白屏幕但使用开发模式
ionic cordova build --prod --release 失败并产生错误
Ionic 3 - 使用 --prod 标志运行时,sqlite 显示“无法读取 openDatabase 的属性”的错误