科尔多瓦应用程序意外关闭

时间:2016-06-11 15:56:00

标签: android cordova ionic-framework cordova-plugins crash

我使用cordova开发了一个混合应用程序。我上传到谷歌播放和应用程序商店。用户报告说他们收到了一条消息"不幸的是,xxx已关闭" (xxx代表应用名称)。在测试时我无法重现该问题。奇怪的部分是用户在不使用我的应用程序时收到此消息。我在我的应用程序中安装了以下插件

cordova-plugin-camera 2.2.1-dev "Camera"
cordova-plugin-compat 1.0.0 "Compat"
cordova-plugin-device 1.1.1 "Device"
cordova-plugin-file 4.1.0 "File"
cordova-plugin-file-transfer 1.5.0 "File Transfer"
cordova-plugin-geolocation 2.1.0 "Geolocation"
cordova-plugin-inappbrowser 1.4.0 "InAppBrowser"
cordova-plugin-network-information 1.2.0 "Network Information"
cordova-plugin-splashscreen 3.2.2 "Splashscreen"
cordova-plugin-statusbar 2.1.4-dev "StatusBar"
cordova-plugin-whitelist 1.2.2 "Whitelist"
cordova-plugin-x-toast 2.3.2 "Toast"
cordova-sqlite-storage 0.7.14 "Cordova sqlite storage plugin"
cordova.plugins.diagnostic 3.0.2 "Diagnostic"
ionic-plugin-keyboard 2.2.0 "Keyboard"
phonegap-plugin-barcodescanner 5.0.0 "BarcodeScanner"
phonegap-plugin-push 1.6.4 "PushPlugin"

Ios用户没有收到此崩溃消息。只有Android用户才报告此问题。

这是我的Androidmanifest.xml文件

<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="1" android:versionName="0.0.1" package="com.xxx.yy" xmlns:android="http://schemas.android.com/apk/res/android">
    <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
    <uses-permission android:name="android.permission.INTERNET" />
    <application android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name" android:supportsRtl="true">
        <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:screenOrientation="portrait" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">
            <intent-filter android:label="@string/launcher_name">
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <receiver android:name="cordova.plugins.Diagnostic$LocationProviderChangedReceiver">
            <intent-filter>
                <action android:name="android.location.PROVIDERS_CHANGED" />
            </intent-filter>
        </receiver>
        <activity android:clearTaskOnLaunch="true" android:configChanges="orientation|keyboardHidden|screenSize" android:exported="false" android:name="com.google.zxing.client.android.CaptureActivity" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:windowSoftInputMode="stateAlwaysHidden">
            <intent-filter>
                <action android:name="com.google.zxing.client.android.SCAN" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity android:label="Share" android:name="com.google.zxing.client.android.encode.EncodeActivity">
            <intent-filter>
                <action android:name="com.phonegap.plugins.barcodescanner.ENCODE" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity android:label="Share" android:name="com.google.zxing.client.android.HelpActivity">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity android:exported="true" android:name="com.adobe.phonegap.push.PushHandlerActivity" />
        <receiver android:name="com.adobe.phonegap.push.BackgroundActionButtonHandler" />
        <receiver android:exported="true" android:name="com.google.android.gms.gcm.GcmReceiver" android:permission="com.google.android.c2dm.permission.SEND">
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <category android:name="${applicationId}" />
            </intent-filter>
        </receiver>
        <service android:exported="false" android:name="com.adobe.phonegap.push.GCMIntentService">
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            </intent-filter>
        </service>
        <service android:exported="false" android:name="com.adobe.phonegap.push.PushInstanceIDListenerService">
            <intent-filter>
                <action android:name="com.google.android.gms.iid.InstanceID" />
            </intent-filter>
        </service>
        <service android:exported="false" android:name="com.adobe.phonegap.push.RegistrationIntentService" />
    </application>
    <uses-sdk android:minSdkVersion="16" android:targetSdkVersion="23" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.FLASHLIGHT" />
    <uses-feature android:name="android.hardware.camera" android:required="false" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    <permission android:name="${applicationId}.permission.C2D_MESSAGE" android:protectionLevel="signature" />
    <uses-permission android:name="${applicationId}.permission.C2D_MESSAGE" />
</manifest>

我的代码中有两个函数,它们会自动调用。两者都用于将数据同步到服务器。

$interval(function() {
        var isOnline = $cordovaNetwork.isOnline();
        if (isOnline) {
            $scope.syncData();
        }
    }, 900000)

$rootScope.$on('$cordovaNetwork:online', function(event, networkState) {
        if ($scope.isLoggedIn) {
            var onlineState = networkState;
            console.log('Online State', onlineState);
            $scope.syncData();
        }

    });

这个函数会在后台调用吗? app关闭后这个功能会持续吗? 调试期间我找不到任何异常。 任何人都可以帮助我吗?

更新

我发现发生了两种情况:

  1. 由于网络问题,我正在将网络状态更改为飞行模式 问题。突然间我收到了不幸的是xxx已经停止的消息
  2. 我的GPS已停用。我试图打开谷歌地图。我有一个 来自谷歌地图的消息以启用GPS。当我启用GPS时,我 得到消息,不幸的是xxx已经停止了

1 个答案:

答案 0 :(得分:1)

正如this question中所述,这是由cordova.plugins.diagnostic@3.0.2中的错误导致的,在issue #85中标记为plugin repo,并由补丁发布cordova.plugins.diagnostic@3.0.4解决。更新插件并重建应用程序应该可以解决问题:

$ cordova plugin rm cordova.plugins.diagnostic && 
  cordova plugin add cordova.plugins.diagnostic@3.0.4 &&
  cordova build android --release