我正在使用 firebase Admin SDK 并且我在運(yùn)行時(shí)收到此錯(cuò)誤:Error:(22, 36) java: cannot access com.google.auth.Credentialsclass file for com.google.auth.Credentials not found這是拋出錯(cuò)誤的構(gòu)造函數(shù)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 會(huì)引發(fā)錯(cuò)誤,但我找不到解決方案。這是我的 build.gradle 文件...group 'src'version '1.0-SNAPSHOT'apply plugin: 'java'sourceCompatibility = 1.8repositories { mavenCentral()}dependencies { testCompile group: 'junit', name: 'junit', version: '4.12' implementation 'com.google.firebase:firebase-admin:6.5.0'}謝謝你的幫助。
1 回答

月關(guān)寶盒
TA貢獻(xiàn)1772條經(jīng)驗(yàn) 獲得超5個(gè)贊
不久前,當(dāng)我嘗試在我們的應(yīng)用引擎項(xiàng)目中進(jìn)行 Firebase 集成時(shí),我遇到了同樣的問題。這是由您在 google 庫中的應(yīng)用程序中具有的某種瞬態(tài)依賴性引起的。
請嘗試這些東西,
如果您使用的是較低版本的 appengine-api,請將其升級到appengine-api-1.0-sdk-1.9.64.jar或更高版本。
然后檢查您的依賴項(xiàng)。如果您正在使用其中任何一種,
google-oauth-client-1.22.0.jar
google-oauth-client-appengine-1.22.0.jar
google-oauth-client-servlet-1.22.0.jar
這可能就是沖突。嘗試刪除它們(您可能不需要它們)。希望能幫助到你。
添加回答
舉報(bào)
0/150
提交
取消