让 Firebase 使用 java,而不是 Android [英] Get Firebase to work with java, not Android

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

问题描述

我正在尝试启动并运行一个 libgdx 项目,并且我想使用 firebase 进行用户登录.我发现 SimleLogin 类依赖于 Android.jar.有没有办法解决这个问题,因为我想让桌面 java 应用程序和 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.

这是导致问题的代码:

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);
                }

            }
        });

这在运行时抛出这个:

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

我要这样做还是他们声称支持的 Java 平台真的只是 android?

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

推荐答案

Firebase 的 Java 产品有两个部分,每个部分都有不同的依赖项:

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

Firebase Java 客户端库 - 使用这个访问 Firebase 实时数据库.

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

文档有点偏向于 Android,但它在 Java 和可以调用 Java 的语言(例如 Groovy)中运行良好

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 简单登录库 - 这使身份验证更容易,但如果您愿意,您可以自己处理身份验证.

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

此库仅适用于 Android.通常,身份验证通常以一堆特定于平台的技巧告终.该库专注于 Android 中的这些技巧.

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.

听起来你想在 libgdx 中进行身份验证.您能否扩展您的问题以包含更多有关您预期的用例的信息?

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

(复制自上述@Ossama 的评论)

(copied from @Ossama's comment above)

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

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