Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Firebase to work with java, not Android

Im trying to get a libgdx project up and running and I want to firebase for user logins. I'm finding that the SimleLogin class is depending on Android.jar. Is there a way around this as I would like to have a desktop java application running as well as android.

Here is the code that is causing the issue:

SimpleLogin authClient = new SimpleLogin(myRef);;

authClient.createUser("[email protected]", "much wow",
        new SimpleLoginAuthenticatedHandler() {

            @Override
            public void authenticated(FirebaseSimpleLoginError error,
                    FirebaseSimpleLoginUser user) {
                if (error != null) {
                    System.out.println(error);
                } else {
                    System.out.println(user);
                }

            }
        });

And this thowing this at runtime:

Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: java.lang.NoClassDefFoundError: android/net/Uri
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:120)
Caused by: java.lang.NoClassDefFoundError: android/net/Uri
    at com.firebase.simplelogin.SimpleLogin.makeRequest(SimpleLogin.java:634)
    at com.firebase.simplelogin.SimpleLogin.createUser(SimpleLogin.java:417)
    at com.mygdx.game.MyGdxGame.create(MyGdxGame.java:63)
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:136)
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:114)
Caused by: java.lang.ClassNotFoundException: android.net.Uri
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 5 more

Am I going about this or is the Java platform they claim to support really just android?

like image 294
Jim Gorski Avatar asked Aug 08 '14 02:08

Jim Gorski


1 Answers

There are two parts to Firebase's Java offering, each with different dependencies:

Firebase Java client library - Use this to access the Firebase realtime database.

The docs lean a bit towards Android, but it works great in Java and languages that can call out to Java (e.g. Groovy)

Firebase Simple Login library - This makes auth easier, but you can handle auth yourself if you prefer.

This library is Android only. In general, authentication usually ends up with a bunch of platform specific tricks. This library focuses on the Android set of those tricks.

It sounds like you want auth in libgdx. Can you expand your question to include a bit more about your expected use case?

(copied from @Ossama's comment above)

like image 129
mimming Avatar answered Oct 11 '22 06:10

mimming