Firebase Admin NoClassDefFoundError: FirebaseOptions $ Builder

I use this:

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

However, the application crashes using java.lang.NoClassDefFoundError for FirebaseOptions$Builder

My build.gradle :

 dependencies { testCompile group: 'junit', name: 'junit', version: '4.11' compile 'com.google.firebase:firebase-admin:4.1.1' } 

I am using 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) 

I have firebase_key.json in the root application.

What causes this?

+8
android firebase firebase-authentication firebase-admin
source share
2 answers

The problem was that I used this command to build:

 gradlew clean install 

However, the Jar generated by this does not contain dependencies . And the Firebase Admin SDK is a dependency.

So what I did, I used shadowJar , which generates a Jar that contains dependencies. Unlike gradlew clean install .

Then in Procfile I set it to a Jar that generates a shadowJar. The only problem I see is now that I have to go to IntelliJ and run shadowJar from there, since there is no command to run it from the command line.

Hope this helps

+4
source share

You do not install the correct import in the gradle parameters for firebase, there is no need for an administrator package, you need the kernel:

Instead of compile 'com.google.firebase:firebase-admin:4.1.1'

Use compile "com.google.firebase:firebase-core:10.0.1"

+1
source share

All Articles