Gradle setting problem with sending notification via firebase in Android studio

Viewed 440

I tried to enable the sending notification function in my android app via Firebase. Following the tutorials, I added the following code in my AndroidManifest.xml, application tag.

        <meta-data android:name="com.parse.push.gcm_sender_id"
            android:value="id:XXXXXX" />
        <service
            android:name="com.parse.fcm.ParseFirebaseInstanceIdService"
            android:exported="true">
            <intent-filter>
                <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
            </intent-filter>
        </service>

        <service
            android:name="com.parse.fcm.ParseFirebaseMessagingService">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT"/>
            </intent-filter>
        </service>

        <receiver android:name="com.parse.ParsePushBroadcastReceiver" android:exported="false">
            <intent-filter>
                <action android:name="com.parse.push.intent.RECEIVE" />
                <action android:name="com.parse.push.intent.OPEN" />
                <action android:name="com.parse.push.intent.DELETE" />
            </intent-filter>
        </receiver>
        <receiver
            android:name="com.parse.ParsePushBroadcastReceiver"
            android:exported="false">
            <intent-filter>
                <action android:name="com.parse.push.intent.RECEIVE" />
                <action android:name="com.parse.push.intent.DELETE" />
                <action android:name="com.parse.push.intent.OPEN" />
            </intent-filter>
        </receiver>

I also added in the following code in my app build.gradle file, dependency section:

implementation 'com.google.firebase:firebase-messaging:17.3.4'
implementation 'com.google.firebase:firebase-core:16.0.5'

The app build.gradle file looks like:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    buildToolsVersion '27.0.1'

    defaultConfig {
        applicationId "edu.pitt.cs.mips.coursemirror"
        minSdkVersion 19
        targetSdkVersion 27
    }

    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
        }
    }
}

dependencies {
    compile files('libs/Parse-1.13.0.jar')
    compile files('libs/ParseInterceptors-0.0.2.jar')
    compile files('libs/android-pusher-0.6.jar')
    compile files('libs/bolts-tasks-1.4.0-javadoc.jar')
    compile files('libs/bolts-tasks-1.4.0.jar')
    compile files('libs/nineoldandroids-2.4.0.jar')
    compile files('libs/otto-1.3.4.jar')
    compile files('libs/picasso-1.1.1.jar')
    compile files('libs/retrofit-1.5.1.jar')
    compile files('libs/volley.jar')
    compile 'com.google.code.gson:gson:2.2.4'
    compile 'com.android.support:appcompat-v7:27+'
    compile 'com.android.support:support-v4:27.1.1'
    implementation 'com.google.firebase:firebase-messaging:17.3.4'
    implementation 'com.google.firebase:firebase-core:16.0.5'
}

repositories {
    mavenCentral()
    jcenter()
    maven { url 'https://jitpack.io' }
}

repositories {
    mavenLocal()
    mavenCentral()
    maven {
        url 'https://maven.google.com/'
    }
}


apply plugin: 'com.google.gms.google-services'

However, after sync the gradle, there are errors in AndroidManifest.xml:

        <service
            android:name="com.parse.fcm.ParseFirebaseInstanceIdService"
            android:exported="true">
            <intent-filter>
                <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
            </intent-filter>
        </service>

        <service
            android:name="com.parse.fcm.ParseFirebaseMessagingService">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT"/>
            </intent-filter>
        </service>

The errors are: unresolved package 'fcm', and Unresolved class 'ParseFirebaseMessagingService' and 'ParseFirebaseInstanceIdService'. And when I run the code, the push notification function from website and in-app both don't work. To solve this problem, I include the following code in build.gradle file dependency section:

implementation "com.github.parse-community.Parse-SDK-Android:fcm:1.18.5"

However, after sync with this update, when ran the app, it reports the error: "Multiple dex files define Lbolts/Task$UnobservedExceptionHandler;"

Anyone knows how to solve this problem? Thanks a lot!

1 Answers

I've faced the same problem and solve it through this

in your build.gradle (module app)

go to dependencies add this code

    implementation "com.github.parse-community.Parse-SDK-Android:fcm:1.19.0"

This will download the needed files
And if u face a problem with this version try this one work fine for me

    implementation "com.github.parse-community.Parse-SDK-Android:fcm:1.18.6"

source Github Project

Related