3

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.

Community
  • 1
  • 1

2 Answers2

5

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

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
jonnydee
  • 1,311
  • 1
  • 7
  • 11
0

If you are using a Grails application, you need to make it a Java class (i.e. src/main/java). If you put it in src/main/groovy, the problem still exists.

user745852
  • 11
  • 1