2

Here is my build.gradle app file:

dependencies {
    //picture library
    compile 'com.github.bumptech.glide:glide:3.8.0'
    //recycler and card view
    compile 'com.android.support:support-v4:26.+'
    compile 'com.android.support:recyclerview-v7:26.+'
    compile 'com.android.support:cardview-v7:26.+'

    //json
    compile 'com.google.code.gson:gson:2.8.5'
    compile 'com.squareup.retrofit2:converter-gson:2.2.0'
    compile 'com.squareup.retrofit2:retrofit:2.4.0'
    //firebase
    compile 'com.google.firebase:firebase-core:16.0.1'
    compile 'com.google.firebase:firebase-messaging:10.0.1'
    testCompile 'junit:junit:4.12'
}

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

Here is my build.gradle Project file

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.3'

        classpath 'com.google.gms:google-services:4.0.1'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()

        maven { url "https://maven.google.com" }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

I am using Firebase Messaging Service, and I want to get notification into my app. So I am just checking the log for any update. My FirebaseMessagingService file is:

public void onMessageReceived(RemoteMessage remoteMessage) {

        Log.d(TAG, "onMessageReceived: "+remoteMessage.getNotification().getTitle());

        Log.d(TAG, "onMessageReceived: "+remoteMessage.getNotification().getBody());

        Log.d(TAG, "onMessageReceived: "+remoteMessage.getData());

    }

While Compiling, I am getting error. How to resolve it?

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
Tony30
  • 51
  • 1
  • 10
  • why you don't post the whole `build.gradle` and why you use such outdated build-tools?? – Martin Zeitler Sep 05 '18 at 07:26
  • Possible duplicate of [FirebaseInitProvider: FirebaseApp initialization unsuccessful](https://stackoverflow.com/questions/37321728/firebaseinitprovider-firebaseapp-initialization-unsuccessful) – Martin Zeitler Sep 05 '18 at 07:32
  • thanks guys just solved by changing version of firebase-messaging to latest version. But token is not generated as it says 'com.google.firebase.iid.FirebaseInstanceIdService' is deprecated,what is alternative method to use? – Tony30 Sep 05 '18 at 08:05

3 Answers3

6

According to the firebase official documentation, please update your dependencies to the latest versions. So please change the following lines of code:

compile 'com.google.firebase:firebase-core:16.0.1'
compile 'com.google.firebase:firebase-messaging:10.0.1'

to

implementation 'com.google.firebase:firebase-core:16.0.3'
implementation 'com.google.firebase:firebase-messaging:17.3.0'

You can also upgrade the gradle of your project to the latest version:

classpath 'com.android.tools.build:gradle:3.1.4'
Chirag Jain
  • 628
  • 11
  • 24
Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
  • this still would need `play-services-base` & `play-services-auth`, as the error message hints for. – Martin Zeitler Sep 05 '18 at 07:33
  • @MartinZeitler According to OP's requirements, Google Play services dependencies should be added accordingly. This is how the OP can [Set Up a Firebase Cloud Messaging Client](https://firebase.google.com/docs/cloud-messaging/android/client). – Alex Mamo Sep 05 '18 at 07:41
  • without the whole `build.gradle` (despite the dependency is completely missing), this is typically is also one of the classes, which can be affected by ProGuard... while it might be true, that only `play-services-base` might be required, meanwhile... the docs there only state `firebase-core`. – Martin Zeitler Sep 05 '18 at 07:46
3

If you are Getting this Error:

error: cannot access zza class file for com.google.android.gms.common.internal.safeparcel.zza not found

Then Use this:

implementation 'com.google.android.gms:play-services-maps:11.8.0'
implementation 'com.google.android.gms:play-services-location:11.8.0'

api 'com.google.firebase:firebase-messaging:17.0.0'

It Works...

Gaurav Lambole
  • 273
  • 3
  • 3
0

add This

    compile 'com.google.firebase:firebase-core:16.0.3'
    compile 'com.google.firebase:firebase-messaging:17.3.0'
Ashvin solanki
  • 4,802
  • 3
  • 25
  • 65