我使用這個:
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 。
的logcat:
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。
這是什麼造成的?
添加您的logcat –
沒想到它是需要的。添加 –