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();
}
}
this is line 22
.setCredentials(GoogleCredentials.fromStream(serviceAccount))
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'
}
Thanks for any help.