将Hibernate添加到Android项目(错误使用核心类)

时间:2012-10-29 04:24:27

标签: java android hibernate

我们主要关注的是基于Java的桌面应用程序。我们的应用程序的数据使用Hibernate存储在H2数据库中。 H2数据库以服务器模式运行,以便其他客户端可以连接到它。

是否可以构建Android应用程序以查看服务器上托管的数据。当我在我的android应用程序li​​bs文件夹中包含hibernate jar时,我会收到以下错误。

   [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项目。

1 个答案:

答案 0 :(得分:0)

Hibernate库适用于台式机和服务器上的JDK应用程序。他们不使用Android。 SqlLite是Hibernate可能永远不适用于Android的主要原因之一。它的使用非常简单。

如果您强行包含它,您将收到Dalvik错误。当您包含2个android.jar或rt.jar时,会遇到相同的错误。