我正在使用firebase Admin SDK并在运行时获取此错误:
Error:(22, 36) java: cannot access com.google.auth.Credentials
class file for com.google.auth.Credentials not found
import com.google.auth.oauth2.GoogleCredentials;
import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaSEOptions;
import com.google.firebase.database.*;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
class Database{
private FirebaseDatabase firebaseDatabase;
Database(){
InputStream serviceAccount = Database.class.getResourceAsstream("reading-incentive-firebase-adminsdk-n556s-1b742e4b58.json");
FirebaSEOptions options;
try {
options = new FirebaSEOptions.Builder()
.setCredentials( GoogleCredentials.fromStream(serviceAccount))
.setDatabaseUrl("https://reading-incentive.firebaseio.com")
.build();
FirebaseApp.initializeApp(options);
} catch (IOException e) {
e.printstacktrace();
System.out.println("Error loading database");
}
firebaseDatabase = FirebaseDatabase.getInstance();
}
}
这是第22行
.setCredentials(GoogleCredentials.fromStream(serviceAccount))
我在IntelliJ中使用java sdk 1.8和gradle.我已阅读其他帖子并阅读使用sdk 1.8 over 1.7抛出错误,但我找不到解决方案.这是我的build.gradle文件…
group 'src'
version '1.0-SNAPSHOT'
apply plugin: 'java'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
implementation 'com.google.firebase:firebase-admin:6.5.0'
}
谢谢你的帮助.
解决方法:
当我试图在我们的应用程序引擎项目中进行firebase集成时,我曾经有同样的问题.这是由于您在Google图书馆中的应用程序中存在的某种暂时依赖性造成的.
请试试这些东西,
如果您使用的是较低版本的appengine-api,请将其升级为appengine-api-1.0-sdk-1.9.64.jar或更高版本.
然后检查你的依赖项.如果您使用其中任何一个,
google-oauth-client-1.22.0.jar
google-oauth-client-appengine-1.22.0.jar
google-oauth-client-servlet-1.22.0.jar
这可能是冲突.尝试删除它们(您可能不需要它们).希望能帮助到你.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。