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

查看:166
本文介绍了java:找不到com.google.auth.Credentials的com.google.auth.Credentials类文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用firebase Admin SDK,并在运行时收到此错误:

I'm using the firebase Admin SDK and im getting this error at runtime:

Error:(22, 36) java: cannot access com.google.auth.Credentials
class file for com.google.auth.Credentials not found

这是引发错误的构造函数

This is the constructor that is throwing the error

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))

.setCredentials(GoogleCredentials.fromStream(serviceAccount))

我正在使用IntelliJ中的java sdk 1.8和gradle.我读过其他文章,并读到在1.7上使用sdk 1.8会引发错误,但我找不到解决方案.这是我的build.gradle文件...

I'm using the java sdk 1.8 in IntelliJ along with gradle. I've read other posts and read that using sdk 1.8 over 1.7 throws the error but I can't find a solution. Here is my build.gradle file...

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'
}

感谢您的帮助.

推荐答案

当我尝试在我们的App Engine项目中进行Firebase集成时,我遇到了同样的问题.这是由您在Google库中的应用程序中存在某种暂时性依赖关系引起的.

I had the same issue a while back when I was trying to do the firebase integration in our app engine project. This is caused by a some sort of transient dependency you are having in your application within google libraries.

请尝试这些事情,

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

if you are using lower version of appengine-api upgrade it to appengine-api-1.0-sdk-1.9.64.jar or higher.

然后检查您的依赖项.如果您使用其中任何一种,

then check your dependencies. if you are using either one of these,

google-oauth-client-1.22.0.jar
google-oauth-client-appengine-1.22.0.jar
google-oauth-client-servlet-1.22.0.jar

那可能是冲突.尝试删除它们(您可能不需要它们).希望能帮助到你.

that could be the conflict. try removing them (you might not need them). hope it helps.

这篇关于java:找不到com.google.auth.Credentials的com.google.auth.Credentials类文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆