Java 将Hibernate添加到Android项目(错误使用核心类)
我们主要关注基于java的桌面应用程序。应用程序的数据使用Hibernate存储在H2数据库中。H2数据库以服务器模式运行,以便其他客户端可以连接到它 是否可以构建Android应用程序来查看托管在服务器上的数据。当我在android应用程序libs文件夹中包含hibernate jar时,我会出现以下错误Java 将Hibernate添加到Android项目(错误使用核心类),java,android,hibernate,Java,Android,Hibernate,我们主要关注基于java的桌面应用程序。应用程序的数据使用Hibernate存储在H2数据库中。H2数据库以服务器模式运行,以便其他客户端可以连接到它 是否可以构建Android应用程序来查看托管在服务器上的数据。当我在android应用程序libs文件夹中包含hibernate jar时,我会出现以下错误 [dx] trouble processing "javax/transaction/Transaction.class": [dx] [dx] Ill-advised
[dx] trouble processing "javax/transaction/Transaction.class":
[dx]
[dx] Ill-advised or mistaken usage of a core class (java.* or javax.*)
[dx] when not building a core library.
[dx]
[dx] This is often due to inadvertently including a core library file
[dx] in your application's project, when using an IDE (such as
[dx] Eclipse). If you are sure you're not intentionally defining a
[dx] core class, then this is the most likely explanation of what's
[dx] going on.
[dx]
[dx] However, you might actually be trying to define a class in a core
[dx] namespace, the source of which you may have taken, for example,
[dx] from a non-Android virtual machine project. This will most
[dx] assuredly not work. At a minimum, it jeopardizes the
[dx] compatibility of your app with future versions of the platform.
[dx] It is also often of questionable legality.
[dx]
[dx] If you really intend to build a core library -- which is only
[dx] appropriate as part of creating a full virtual machine
[dx] distribution, as opposed to compiling an application -- then use
[dx] the "--core-library" option to suppress this error message.
[dx]
[dx] If you go ahead and use "--core-library" but are in fact
[dx] building an application, then be forewarned that your application
[dx] will still fail to build or run, at some point. Please be
[dx] prepared for angry customers who find, for example, that your
[dx] application ceases to function once they upgrade their operating
[dx] system. You will be to blame for this problem.
[dx]
[dx] If you are legitimately using some code that happens to be in a
[dx] core package, then the easiest safe alternative you have is to
[dx] repackage that code. That is, move the classes in question into
[dx] your own package namespace. This means that they will never be in
[dx] conflict with core system classes. JarJar is a tool that may help
[dx] you in this endeavor. If you find that you cannot do this, then
[dx] that is an indication that the path you are on will ultimately
[dx] lead to pain, suffering, grief, and lamentation.
[dx]
[dx] 1 error; aborting
有两个必需的Hibernate库使用javax名称空间(Hibernate-jpa-2.0-api.1.0.1-Final.jar和jboss-transaction-api_1.1_spec-1.0.0.Final.jar)
- 它试图将所有库合并到.apk中,并抛出一个异常,因为它发现一个使用保留名称空间的类
- 类可能与作为Android/Java一部分的系统(核心)类冲突
- 使用像JarJar这样的工具会有帮助吗李>
- 重新打包代码如何与许可一起工作李>
- 重新打包所有代码是否困难李>
- 为什么第三方会用javax创建一个包呢
编辑:我使用ant通过自动生成的构建文件和命令“ant debug”编译Android项目。Hibernate库用于桌面和服务器上的JDK应用程序。他们不使用Android。SqlLite是Hibernate可能永远无法为Android工作的主要原因之一。它使用起来很简单
如果强行包含,则会出现Dalvik错误。当包含2个android.jar或rt.jar时,也会出现同样的错误。我想知道你之前是否搜索过。“android hibernate”的前几个结果显然就是你的答案所在。我当然知道。我在这里发帖是因为他们没有回答我的问题。请尽量保持你的评论具有建设性。谢谢。看起来你没有用谷歌搜索过。前两个结果为您提供了问题的答案。这是我的建设性意见,你是说这根本不可能?你对此有什么参考资料吗?和我在谷歌上搜索时一样。。。人们说这太过分了,不使用它。。。但这不适用于我的情况。我遇到了你所说的错误,这就是这个问题的内容。事实上,我已经为桌面应用程序提供了一个使用Hibernate的持久层,并且我需要能够从Android上的SQL server检索数据,该SQL server不在Android设备上,因此也不在SQLite上。我正在寻找潜在的解决方案。如果您的数据托管在服务器上,而不是android设备上,为什么要安装hibernate?你相信hibernate是一个数据库客户端,它会神奇地将你的数据复制到你的android设备上,这样你就不必写一些套接字之类的东西了吗?你的问题和目标刚刚改变。坦率地说,我对你想做什么感到困惑。改变你的问题,让它与你想做的事情更相关?它们不适用于Android。实际上意思是“实际上根本不可能”。我被你的困惑弄糊涂了。我的目标在编译错误之前陈述,我的问题在编译错误之后陈述。有一个SQL数据库正在使用Hibernate将对象映射到它。然后我们想在Android设备上查看数据。由于对象是通过Hibernate保存的(由桌面应用程序保存),因此通过Hibernate加载它们是有意义的(除了我现在知道Hibernate在Android中存在的错误)。如果不可能,我需要找到另一个解决方案。这个问题正在探索许多潜在解决方案中的一个。为什么像JarJar这样的工具不起作用?@shaddow,我想在这里提供帮助,但你似乎不想放弃在android上编译hibernate的立场。伙计,好好研究冬眠。我想你会发现你的基本面需要加强。从技术上讲,对你来说“有意义”的东西是完全错误的。这就像在说,为什么ios代码不能在android上编译,仅仅因为它在看起来像我的android手机的ios上工作。关于这个话题,我没有更多的回应。