问题
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?
回答1:
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)
回答2:
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
来源:https://stackoverflow.com/questions/25195190/get-firebase-to-work-with-java-not-android