RollerMobster
RollerMobster

Reputation: 984

Error: 'cannot find symbol class GetTokenResult' after adding latest firebase-messaging dependency

I want to use FCM in my app, however after adding the latest firebase-messaging dependency:

implementation 'com.google.firebase:firebase-messaging:18.0.0'

I get the following error in the compiler when building the project:

error: cannot find symbol class GetTokenResult

The error comes from FirebaseUserInterceptor that I am using to capture user token, and it works just fine. However, after I add the messaging dependency, both "GetTokenResult" and "getToken()" seem to become unrecognized and thus, throws the error mentioned above.

Code:

import android.util.Log;
import com.google.android.gms.tasks.Task;
import com.google.android.gms.tasks.Tasks;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.auth.GetTokenResult;
import java.io.IOException;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

public class FirebaseUserInterceptor implements Interceptor {

    private static final String X_FIREBASE_ID_TOKEN = "firebaseUserId";
    private static final String TAG = "FirebaseUserInterceptor";

    @Override
    public Response intercept(Chain chain) throws IOException {
        Request request = chain.request();

        try {
            FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
            if (user == null) {
                Log.d(TAG, "intercept: not logged in");
                throw new Exception("User not logged in");
            } else {
                Task<GetTokenResult> task = user.getIdToken(true);
                GetTokenResult tokenResult = Tasks.await(task);
                String idToken = tokenResult.getToken();
                Log.d(TAG, "intercept: token=" + idToken);

                if (idToken == null) {
                    Log.d(TAG, "intercept: idToken null");
                    throw new Exception("idToken null");
                } else {
                    Request modifiedRequest = request.newBuilder()
                            .addHeader(X_FIREBASE_ID_TOKEN, idToken)
                            .build();
                    return chain.proceed(modifiedRequest);
                }
            }
        } catch (Exception e) {
            throw new IOException(e.getMessage());
        }
    }
}

Gradle (App):

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.app_v1"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    configurations {
        all*.exclude group: 'com.google.guava', module: 'listenablefuture'
    }
    buildTypes {
        customDebugType {
            debuggable true
        }
        debug {
            testCoverageEnabled = false
        }
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.preference:preference:1.1.0-alpha05'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'

    //Firebase
    implementation 'com.google.firebase:firebase-core:16.0.8'
    implementation 'com.google.firebase:firebase-auth:16.2.1'
    implementation 'com.google.firebase:firebase-messaging:18.0.0'

    //Retrofit
    implementation 'com.squareup.retrofit2:retrofit:2.5.0'

    //Gson
    implementation 'com.squareup.retrofit2:converter-gson:2.3.0'

    //OkHttpLoggingInterceptor
    implementation 'com.squareup.okhttp3:logging-interceptor:3.4.1'

    //OkHttp
    implementation 'com.squareup.okhttp3:okhttp:3.4.1'

    //GraphView
    implementation 'com.jjoe64:graphview:4.2.2'

    //Room
    implementation 'android.arch.persistence.room:runtime:1.1.1';
    annotationProcessor 'android.arch.persistence.room:compiler:1.1.1';

    //TimeSquare date and date range picker
    implementation 'com.squareup:android-times-square:1.6.5@aar'

    implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
    annotationProcessor 'androidx.lifecycle:lifecycle-compiler:2.0.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    implementation 'androidx.lifecycle:lifecycle-livedata:2.0.0'
    implementation 'androidx.room:room-runtime:2.0.0'
    annotationProcessor 'androidx.room:room-compiler:2.0.0'
}

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

Gradle(Project):

buildscript {
    repositories {
        google()
        jcenter()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.0'
        classpath 'com.google.gms:google-services:4.2.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

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

I am using Android Studio (version 3.4)

Upvotes: 1

Views: 1273

Answers (1)

Peter Haddad
Peter Haddad

Reputation: 80904

Update the following dependency:

implementation 'com.google.firebase:firebase-auth:16.2.1'

into this:

implementation 'com.google.firebase:firebase-auth:17.0.0'

From the docs:

Breaking changes for this update:

If you use Firebase Authentication, update to firebase-auth v17.0.0 or later to ensure functionality alignment with other updated Firebase libraries.

Upvotes: 5

Related Questions