Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to start a Firebase Java client

Tags:

java

firebase

I am trying to start a Java client from scratch, and have pulled in firebase-client-jvm:2.2.1 in gradle. I get the following in a stack trace while trying to compile anything that includes the com.firebase.client.Firebase class:

java.lang.RuntimeException: java.lang.NoClassDefFoundError: Unable to load class com.firebase.client.Firebase due to missing dependency android/content/Context
    at org.codehaus.groovy.control.CompilationUnit.convertUncaughtExceptionToCompilationError(CompilationUnit.java:1083)
...
Caused by: java.lang.NoClassDefFoundError: Unable to load class com.firebase.client.Firebase due to missing dependency android/content/Context

I have no desire to include anything to do with Android, and all of the answers I find state that firebase "supports both" (i.e. Get Firebase to work with java, not Android), but I do not know how to get going.

I cannot find examples or tutorials online showing a "simple" Java-only client, and would appreciate any "getting started" help.

UPDATE: Not only did I have to create the android.context.Context class, I had to give up on writing the program in Groovy. When I switched it back to a Java project it seemed to smooth things out considerably.

like image 301
Sulley Obrecht Avatar asked Feb 14 '26 00:02

Sulley Obrecht


1 Answers

This is a known bug of the Firebase library with dynamic languages on the JVM. There is an easy workaround: Create an empty dummy class Context in the package android.content. The class is not used at runtime, however the class loader expects it to be present.

See: https://groups.google.com/forum/#!msg/firebase-talk/XLbpLpqCdDI/ncuw32Xr-4YJ

like image 195
jonnydee Avatar answered Feb 15 '26 12:02

jonnydee



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!