簡體   English   中英

java:無法訪問 com.google.auth.Credentials 未找到 com.google.auth.Credentials 的類文件

[英]java: cannot access com.google.auth.Credentials class file for com.google.auth.Credentials not found

我正在使用 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

這可能就是沖突。 嘗試刪除它們(您可能不需要它們)。 希望能幫助到你。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM