我正在使用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和gradle中的java sdk 1.8。我已经阅读了其他帖子并了解到使用sdk 1.8而不是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'
}
感谢任何帮助。