Ionic 应用程序无法在 android 设备中打开(崩溃)

Ionic app not opening(Crashing) in android device

我正在开发 Ionic 3 应用程序,该应用程序在所有设备上都运行良好,但突然间,当我尝试打开它时,它会立即关闭。 应用程序在浏览器和构建路径中运行良好。 "platforms\android\app\build\outputs\apk\debug\app-debug.apk" 我注意到一件事,为什么 apk 在调试文件夹中构建?

我尝试删除 node_module、平台。

这是我的离子信息:

@ionic/cli-utils  : 1.9.2
ionic (Ionic CLI) : 3.9.2

全局包:

Cordova CLI : 8.0.0

本地包:

@ionic/app-scripts : 3.1.8
Cordova Platforms  : android 7.0.0
Ionic Framework    : ionic-angular 3.9.2

系统:

Android SDK Tools : 26.1.1
Node              : v8.11.0
npm               : 5.6.0
OS                : Windows 7

插件列表:

call-number 0.0.2 "Cordova Call Number Plugin"
cordova-plugin-app-update 1.6.0 "AppUpdate"
cordova-plugin-appversion 1.0.0 "App Version"
cordova-plugin-camera 2.4.1 "Camera"
cordova-plugin-compat 1.2.0 "Compat"
cordova-plugin-console 1.1.0 "Console"
cordova-plugin-device 2.0.3 "Device"
cordova-plugin-fcm-with-dependecy-updated 2.4.0 "Cordova FCM Push Plugin"
cordova-plugin-file 5.0.0 "File"
cordova-plugin-file-transfer 1.7.1 "File Transfer"
cordova-plugin-filepath 1.0.2 "FilePath"
cordova-plugin-geolocation 4.0.2 "Geolocation"
cordova-plugin-inappbrowser 3.1.0 "InAppBrowser"
cordova-plugin-ionic-keyboard 2.1.3 "cordova-plugin-ionic-keyboard"
cordova-plugin-ionic-webview 1.2.1 "cordova-plugin-ionic-webview"
cordova-plugin-nativegeocoder 3.2.2 "NativeGeocoder"
cordova-plugin-splashscreen 5.0.3 "Splashscreen"
cordova-plugin-whitelist 1.3.4 "Whitelist"
cordova-plugin-x-socialsharing 5.4.7 "SocialSharing"
es6-promise-plugin 4.2.2 "Promise"
ionic-plugin-keyboard 2.2.1 "Keyboard"

config.xml

 <widget android-versionCode="" id="" version="1.2.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>****</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-navigation href="data:*" />
<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="ShowSplashScreen" value="false" />
<preference name="AutoHideSplashScreen" value="false" />
<preference name="auto-hide-splash-screen" value="false" />
<plugin name="cordova-plugin-ionic-webview" spec="^1.2.1" />
<plugin name="cordova-plugin-ionic-keyboard" spec="^2.0.5" />
<allow-navigation href="http://192.168.0.16:8100" />
<plugin name="cordova-plugin-filepath" spec="~1.0.2" />
<plugin name="cordova-plugin-file" spec="^5.0.0" />
<plugin name="cordova-plugin-file-transfer" spec="^1.7.1" />
<plugin name="ionic-plugin-keyboard" spec="^2.2.1" />
<plugin name="cordova-plugin-x-socialsharing" spec="^5.4.1" />
<plugin name="cordova-plugin-app-update" spec="^1.6.0" />
<plugin name="cordova-plugin-splashscreen" spec="~5.0.2" />
<plugin name="cordova-plugin-nativegeocoder" spec="^3.2.2" />
<plugin name="cordova-plugin-geolocation" spec="^4.0.1">
    <variable name="GEOLOCATION_USAGE_DESCRIPTION" value="To locate you" />
</plugin>
<plugin name="cordova-plugin-camera" spec="~2.4.1" />
<preference name="SplashScreen" value="screen" />
<preference name="SplashShowOnlyFirstTime" value="false" />
<preference name="SplashScreenDelay" value="3000" />
<plugin name="cordova-plugin-console" spec="^1.1.0" />
<engine androidspec="^6.3.0" name="" />
<plugin name="cordova-plugin-device" spec="^2.0.3" />
<plugin name="mx.ferreyra.callnumber" spec="~0.0.2" />
<plugin name="cordova-plugin-whitelist" spec="^1.3.4" />
<plugin name="cordova-plugin-inappbrowser" spec="^3.0.0" />
<platform name="android">
    <resource-file src="google-services.json" target="google-services.json" />
    <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>
<engine name="android" spec="7.0.0" />
<plugin name="cordova-plugin-fcm-with-dependecy-updated" spec="^2.4.0" />

为什么应用程序无法在 android 设备上正常打开请指出可能出了什么问题?

您是否尝试删除 android 平台并在之后添加? 就这样:

ionic cordova platform remove android
ionic cordova platform add android

我遇到了同样的问题,不知道为什么,但我这样做了,而且效果很好。

1.remove android 平台使用

ionic cordova platform remove android
  1. 手动删除 node-modulespackage-lock.json (imp*)

  2. Unistall 旧应用程序

  3. npm cache clean --force

终于运行npm install

要在 Ionic 中生成发布 Apk:

  • 在 platform/android

    中使用以下代码片段创建 release-signing.properties 文件

    key.store=xxx.keystore key.store.密码=xxx key.alias=xxx key.alias.password=xxx

  • 将您的密钥库文件粘贴到 platform/android 目录

  • 最后,运行 ionic cordova build android -- release 生成release apk

能否分享应用关闭时的日志报告。您可以在 chrome://inspect.

中查看调试应用程序的日志

在我的 ionic v3 应用程序中,当我遇到同样的问题时,问题出在 network_security_config.xml 文件中,我的应用程序也根本没有启动,我必须删除一个域

<domain includeSubdomains="true">myurl.com</domain>

我不得不从提到的文件中删除这样的域,希望它能帮助别人

如果您更改了 spalshscreen 或在 config.xml 中放置了错误的启动画面图像,则意味着应用程序将打开并检查启动画面图像(如果未获取)表示应用程序将被关闭。 所以更好的解决方法是复制旧项目config.xml代码并将其放入新项目然后它会正常工作...... 然后如果你不打开也意味着。

ionic cordova platform remove android    

然后

ionic cordova platform add android    

它会起作用

这通常是您应用程序的运行时错误。例如,尝试通过 运行 具有调试信息 (ionic serve) 的应用程序获取有关该问题的更多信息。