Get Firebase to work with java, not Android(让 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:让 Firebase 使用 java,而不是 Android
基础教程推荐
- 如何使用 Eclipse 检查调试符号状态? 2022-01-01
- 如何对 HashSet 进行排序? 2022-01-01
- Spring Boot Freemarker从2.2.0升级失败 2022-01-01
- Java 中保存最后 N 个元素的大小受限队列 2022-01-01
- 首次使用 Hadoop,MapReduce Job 不运行 Reduce Phase 2022-01-01
- 如何在不安装整个 WTP 包的情况下将 Tomcat 8 添加到 Eclipse Kepler 2022-01-01
- 如何使用 Stream 在集合中拆分奇数和偶数以及两者的总和 2022-01-01
- 如何强制对超级方法进行多态调用? 2022-01-01
- 由于对所需库 rt.jar 的限制,对类的访问限制? 2022-01-01
- 在螺旋中写一个字符串 2022-01-01