Search code examples
androidandroid-manifestbuild.gradlefirebase-cloud-messagingphonegap-pushplugin

Ionic 2 app stops everytime it received a push notification


The App is getting registration number, but when it received a push notification, the app stop and gives the following error:

Unfortunately "APP NAME" has stopped in android

Im using phonegap-plugin-push => https://ionicframework.com/docs/native/push/

I already added google-services.json inside appName/platforms/android/

Here is my build.gradle

buildscript {
    repositories {
        mavenCentral()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'
    }
}
dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    // SUB-PROJECT DEPENDENCIES START
    debugCompile(project(path: "CordovaLib", configuration: "debug"))
    releaseCompile(project(path: "CordovaLib", configuration: "release"))
    compile "com.google.android.gms:play-services-maps:11.+"
    compile "com.google.android.gms:play-services-location:11.+"
    compile "com.stripe:stripe-android:4.1.2"
    compile "com.android.support:support-v13:25.1.0"
    compile "me.leolin:ShortcutBadger:1.1.17@aar"
    compile "com.google.firebase:firebase-messaging:11.0.1"
}

Here is my AndroidManifest.xml

<application android:hardwareAccelerated="true" android:icon="@mipmap/icon" android:label="@string/app_name" android:supportsRtl="true">
    <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
    <activity android:exported="true" android:name="com.adobe.phonegap.push.PushHandlerActivity" android:permission="${applicationId}.permission.PushHandlerActivity" />
    <receiver android:name="com.adobe.phonegap.push.BackgroundActionButtonHandler" />
    <receiver android:name="com.adobe.phonegap.push.PushDismissedHandler" />
    <service android:name="com.adobe.phonegap.push.FCMService">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>
    <service android:name="com.adobe.phonegap.push.PushInstanceIDListenerService">
        <intent-filter>
            <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
        </intent-filter>
    </service>
</application>
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="25" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />

Is anybody here who experienced the same?


Solution

  • I faced the same issue and I was using ionic 1. I've edited my com.android.gms version to match with firebase-messaging version in platforms/android/project.properties file.

    cordova.system.library.1=com.google.android.gms:play-services-location:11.+
    cordova.system.library.6=com.google.firebase:firebase-messaging:11.+
    

    to

    cordova.system.library.1=com.google.android.gms:play-services-location:11.0.1
    cordova.system.library.6=com.google.firebase:firebase-messaging:11.0.1
    

    It is now working as expected.