deluxan
deluxan

Reputation: 422

How to get Firebase Token in android activity?

I am using setToken(FirebaseInstanceId.getInstance().getToken()) code to get the token but I am getting the following error

java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/util/zzv;

build.gradle

dependencies {
    implementation 'de.hdodenhof:circleimageview:2.2.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.squareup.retrofit2:retrofit:2.4.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
    implementation 'com.squareup.okhttp3:okhttp:3.10.0'
    implementation 'android.arch.lifecycle:extensions:1.1.0'
    implementation 'com.google.firebase:firebase-auth:16.0.5'
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    annotationProcessor "android.arch.lifecycle:compiler:1.1.0"
    //noinspection GradleCompatible
    implementation 'com.android.support:recyclerview-v7:28.0.0-rc02'
    implementation 'pub.devrel:easypermissions:0.4.0'
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:design:28.0.0-rc02'
    implementation 'com.google.firebase:firebase-messaging:11.8.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

    implementation 'net.bohush.geometricprogressview:geometricprogressview:1.1.1'
    implementation project(path: ':andoird-sdk')
    implementation project(path: ':opentok-android-sdk-2.16.3')

    implementation 'com.android.support:multidex:1.0.3'
}

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

The above code is my build.gradle. Help me to fix the issue.

Upvotes: 0

Views: 179

Answers (2)

javadroid
javadroid

Reputation: 1431

First of all fix version of all firebase library to latest version. you cant mix versions <= 12 and versions >= 15 of Firebase libraries as mentioned here

then check you have properly enable Multidex on your project. Enable multidex for apps with over 64K methods

then use build -> clean to cleanup your project and dependencies. and for using token use the way of @sonali:

Upvotes: 1

Sonali Kale
Sonali Kale

Reputation: 136

you need to use FirebaseMessagingService to get token .. you will get token into its own method

public class MyFirebaseMessagingService extends FirebaseMessagingService {

@Override
    public void onNewToken(final String token) {

/// you will get token here you 
    enter code here

}

}

Upvotes: 2

Related Questions