gpt4 book ai didi

java - 错误 : 'cannot find symbol class GetTokenResult' after adding latest firebase-messaging dependency

转载 作者:行者123 更新时间:2023-11-29 14:58:13 26 4
gpt4 key购买 nike

我想在我的应用程序中使用 FCM,但是在添加最新的 firebase-messaging 依赖项之后:

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

我在构建项目时在编译器中遇到以下错误:

error: cannot find symbol class GetTokenResult

错误来自于我用来捕获用户 token 的 FirebaseUserInterceptor,它工作正常。但是,在我添加消息依赖项之后,“GetTokenResult”和“getToken()”似乎都无法识别,因此会引发上述错误。

代码:

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 (应用程序):

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 (项目):

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
}

我正在使用 Android Studio(3.4 版)

最佳答案

更新以下依赖:

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

进入这个:

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

来自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.

关于java - 错误 : 'cannot find symbol class GetTokenResult' after adding latest firebase-messaging dependency,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56100491/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com