我正在使用这个:
FileInputStream serviceAccount;
try {
serviceAccount = new FileInputStream("firebase_key.json");
} catch (FileNotFoundException e) {
System.out.println(e.getMessage());
return;
}
System.out.println("Reached here!");
FirebaseOptions options = new FirebaseOptions.Builder()
.setCredential(FirebaseCredentials.fromCertificate(serviceAccount))
.setDatabaseUrl("https://*.firebaseio.com/")
.build();
FirebaseApp.initializeApp(options);
但是,应用程序崩溃了java.lang.NoClassDefFoundError for FirebaseOptions$Builder
我的build.gradle
:
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
compile 'com.google.firebase:firebase-admin:4.1.1'
}
我正在使用 IntelliJ。
日志猫:
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/firebase/FirebaseOptions$Builder
10:57:43 AM web.1 | at com.x.*.TokenGenerator.main(TokenGenerator.java:26)
10:57:43 AM web.1 | Caused by: java.lang.ClassNotFoundException: com.google.firebase.FirebaseOptions$Builder
10:57:43 AM web.1 | at java.net.URLClassLoader.findClass(Unknown Source)
10:57:43 AM web.1 | at java.lang.ClassLoader.loadClass(Unknown Source)
10:57:43 AM web.1 | at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
10:57:43 AM web.1 | at java.lang.ClassLoader.loadClass(Unknown Source)
我的 firebase_key.json 在应用程序的根目录中。
这是什么原因造成的?