获取Firebase以使用Java而不是Android [英] Get Firebase to work with java, not Android

查看:168
本文介绍了获取Firebase以使用Java而不是Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让一个libgdx项目启动并运行,我想为用户登录的firebase。我发现SimleLogin类取决于Android.jar。有没有办法解决这个问题,因为我想有一个桌面Java应用程序运行以及Android。



这是导致问题的代码:

  SimpleLogin authClient = new SimpleLogin(myRef);; 

authClient.createUser(myuser@gmail.com,much wow,
SimpleLoginAuthenticatedHandler(){

@Override
public void已验证(FirebaseSimpleLoginError错误,
FirebaseSimpleLoginUser用户){
if(error!= null){
System.out.println(error);
} else {
System .out.println(user);
}

}
});

而且这个在运行时显示:

<$线程LWJGL应用程序中的异常com.badlogic.gdx.utils.GdxRuntimeException:java.lang.NoClassDefFoundError:android / net / Uri
at com.badlogic.gdx.backends .lwjgl.LwjglApplication $ 1.run(LwjglApplication.java:120)
由com.firebase.simplelogin.SimpleLogin.makeRequest(SimpleLogin.java)导致:java.lang.NoClassDefFoundError:android / net / Uri
: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)
导致:java.lang.ClassNotFoundException:android.net.Uri $ b $在java.net.URLClassLoader $ 1.run(未知来源)$ b $在java.net.URLClassLoader $ 1.run(未知来源)$ b $ ja在ja va.security.AccessController.doPrivileged(Native方法)$ b $在java.net.URLClassLoader.findClass(未知源)$ b $在java.lang.ClassLoader.loadClass(未知源)
在太阳。 misc.Launcher $ AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 5 more

我正在谈论这个问题还是他们声称支持的Java平台真的只是android吗?

解决方案

Firebase的Java产品有两个部分,每个部分都有不同的依赖关系:
$ b Firebase Java客户端库 - 使用它来访问Firebase实时数据库。

文档偏向于Android,但在Java和可以调用Java的语言(例如Groovy)方面效果很好

Firebase简单登录库 - 这使auth更容易,但你可以自己处理auth。



这个库仅适用于Android。一般来说,身份验证通常会结束一堆特定于平台的技巧。这个库专注于这些技巧的Android设置。



这听起来像你想要在libgdx auth。你可以扩展你的问题,包括更多关于你的预期用例吗?



(从上面的@ Ossama的评论复制)

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?

解决方案

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)

这篇关于获取Firebase以使用Java而不是Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆