首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >java:找不到com.google.auth.Credentials,无法访问com.google.auth.Credentials类文件

java:找不到com.google.auth.Credentials,无法访问com.google.auth.Credentials类文件
EN

Stack Overflow用户
提问于 2018-10-06 02:31:49
回答 1查看 2.1K关注 0票数 6

我使用的是firebase Admin SDK,而im在运行时得到了这个错误:

代码语言:javascript
复制
Error:(22, 36) java: cannot access com.google.auth.Credentials
class file for com.google.auth.Credentials not found

这是抛出错误的构造函数

代码语言:javascript
复制
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 SDK1.8和gradle。我读过其他文章,读到使用sdk 1.8而不是1.7会抛出这个错误,但我找不到解决方案。这是我的build.gradle文件...

代码语言:javascript
复制
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'
}

谢谢你的帮助。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-10-06 04:39:15

不久前,当我试图在我们的应用程序引擎项目中进行firebase集成时,我也遇到了同样的问题。这是由于您在google库中的应用程序中存在某种短暂的依赖。

请尝试一下这些东西,

如果您使用的是较低版本的appengine-api,请将其升级到appengine-api-1.0-sdk-1.9.64.jar或更高版本。

然后检查你的依赖关系。如果您使用这两种方法中的一种,

代码语言:javascript
复制
google-oauth-client-1.22.0.jar
google-oauth-client-appengine-1.22.0.jar
google-oauth-client-servlet-1.22.0.jar

这可能就是冲突所在。尝试删除它们(您可能不需要它们)。希望能有所帮助。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52671448

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档