7

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("myuser@gmail.com", "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?

Jim Gorski
  • 360
  • 1
  • 5
  • 16
  • 1
    I'm not sure if it recently changed, but this page (https://www.firebase.com/docs/android/) shows Android only. So I indeed doubt it works (unmodified) on non-Android Java platforms. A quick scan of Stack Overflow questions seems to hint that non-Android Java users are accessing Firebase using its REST API. See http://stackoverflow.com/questions/22252636/create-http-patch-request-to-firebase-from-java-spring – Frank van Puffelen Aug 08 '14 at 13:15
  • 4
    The Firebase Java SDK supports both Android and plain Java, however the Firebase Simple Login library currently only supports Android. Most people use custom login when they're not running on a mobile device. Can you elaborate on what you're trying to accomplish? – Ossama Aug 08 '14 at 16:29

2 Answers2

5

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)

mimming
  • 13,974
  • 3
  • 45
  • 74
  • 1
    Could you update your answer and add a code to make it work on java(not on Android) with new firebase.google.com , because there is some google-services.json file – NickUnuchek Oct 31 '16 at 11:31
4

Firebase client comes in 2 flavors. One is with Android and other is for JVM. Unfortunately by default you will get Android version only.

You will find out JVM version from change log.

Sep 24, 2015 - Version 2.4.0 (Android) (JVM)

I think using JVM jar will resolve this problem.

Old comments: Please use following jar for Java SDK https://cdn.firebase.com/java/firebase-client-jvm-2.4.0.jar

I got above link https://www.firebase.com/docs/android/changelog.html

Nikhil
  • 570
  • 5
  • 12