And*_*chl 6 java gradle firebase firebase-admin
我正在使用 firebase Admin SDK 并且我在运行时收到此错误:
Error:(22, 36) java: cannot access com.google.auth.Credentials
class file for com.google.auth.Credentials not found
Run Code Online (Sandbox Code Playgroud)
这是抛出错误的构造函数
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();
}
}
Run Code Online (Sandbox Code Playgroud)
这是第 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'
}
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助。
不久前,当我尝试在我们的应用程序引擎项目中进行 Firebase 集成时,我遇到了同样的问题。这是由您在谷歌库中的应用程序中存在的某种暂时依赖性引起的。
请尝试这些事情,
如果您使用的是较低版本的 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
Run Code Online (Sandbox Code Playgroud)
这可能就是冲突。尝试删除它们(您可能不需要它们)。希望能帮助到你。
| 归档时间: |
|
| 查看次数: |
1977 次 |
| 最近记录: |