Java库在通过Android项目引用一个Android库抛出NoClassDefFound [英] Java Library in an Android library referenced by an Android Project throws NoClassDefFound

查看:134
本文介绍了Java库在通过Android项目引用一个Android库抛出NoClassDefFound的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Android库项目(我写的,我有来源),我在我的Andr​​oid项目使用 - 到目前为止好,没有问题。但在该库项目,我引用一个国外的.jar文件(SDK为BIXOLON便携式打印机),并建立正常,我可以在我的code参考SDK中的方法。然而,在运行时我得到这样的:

I have an Android library project (written by me and I have the sources) which I use in my Android project - so far so good and no problems. But in that library project I am referencing a foreign .jar file (the SDK for the Bixolon Mobile Printer) and it builds fine and I can reference the SDK's method in my code. However at runtime I get this:

   02-16 09:44:43.620: W/dalvikvm(25402): VFY: unable to resolve virtual method 2433: Lcom/bixolon/android/library/BxlService;.GetStatus ()I
    02-16 09:44:43.625: W/dalvikvm(25402): VFY: unable to resolve virtual method 2433: Lcom/bixolon/android/library/BxlService;.GetStatus ()I
    02-16 09:44:43.625: W/dalvikvm(25402): VFY: unable to resolve virtual method 2436: Lcom/bixolon/android/library/BxlService;.MarkFeed (I)I
    02-16 09:44:43.625: W/dalvikvm(25402): VFY: unable to resolve virtual method 2428: Lcom/bixolon/android/library/BxlService;.Directio ([BI[B[I)I
    02-16 09:44:43.630: W/dalvikvm(25402): VFY: unable to resolve virtual method 2437: Lcom/bixolon/android/library/BxlService;.PrintImage (Ljava/lang/String;III)I
    02-16 09:44:43.630: W/dalvikvm(25402): VFY: unable to resolve virtual method 2433: Lcom/bixolon/android/library/BxlService;.GetStatus ()I
    02-16 09:44:43.630: W/dalvikvm(25402): VFY: unable to resolve virtual method 2433: Lcom/bixolon/android/library/BxlService;.GetStatus ()I
    02-16 09:44:43.630: W/dalvikvm(25402): VFY: unable to resolve virtual method 2433: Lcom/bixolon/android/library/BxlService;.GetStatus ()I
    02-16 09:44:43.790: W/dalvikvm(25402): threadid=1: thread exiting with uncaught exception (group=0x4001e578)
    02-16 09:44:43.795: E/AndroidRuntime(25402): FATAL EXCEPTION: main
    02-16 09:44:43.795: E/AndroidRuntime(25402): java.lang.NoClassDefFoundError: com.bixolon.android.library.BxlService
    02-16 09:44:43.795: E/AndroidRuntime(25402):    at de.softcon.mobileapp.framework.core.bluetooth.printer.bixolon.BixolonPrinter.connectToPrinter(BixolonPrinter.java:71)
    02-16 09:44:43.795: E/AndroidRuntime(25402):    at de.softcon.mobileapp.framework.core.bluetooth.printer.PrintManager.findPrinter(PrintManager.java:101)
    02-16 09:44:43.795: E/AndroidRuntime(25402):    at de.softcon.mobileapp.framework.core.bluetooth.printer.PrintManager.getPrinter(PrintManager.java:77)

02-16 09:44:43.795: E/AndroidRuntime(25402):    at de.softcon.mobileapp.framework.core.bluetooth.printer.PrintManager.printTestReceipt(PrintManager.java:53)
02-16 09:44:43.795: E/AndroidRuntime(25402):    at de.softcon.mobileoffences.ui.Printer$1.execute(Printer.java:40)
02-16 09:44:43.795: E/AndroidRuntime(25402):    at de.softcon.mobileapp.framework.ui.Dialog.executeActions(Dialog.java:271)
02-16 09:44:43.795: E/AndroidRuntime(25402):    at de.softcon.mobileapp.framework.ui.widgets.DynamicWidget.executeActions(DynamicWidget.java:152)
02-16 09:44:43.795: E/AndroidRuntime(25402):    at de.softcon.mobileapp.framework.ui.widgets.DynamicWidget.executeActions(DynamicWidget.java:138)
02-16 09:44:43.795: E/AndroidRuntime(25402):    at de.softcon.mobileapp.framework.ui.widgets.Button$1.onClick(Button.java:67)
02-16 09:44:43.795: E/AndroidRuntime(25402):    at android.view.View.performClick(View.java:2538)
02-16 09:44:43.795: E/AndroidRuntime(25402):    at android.view.View$PerformClick.run(View.java:9152)
02-16 09:44:43.795: E/AndroidRuntime(25402):    at android.os.Handler.handleCallback(Handler.java:587)
02-16 09:44:43.795: E/AndroidRuntime(25402):    at android.os.Handler.dispatchMessage(Handler.java:92)
02-16 09:44:43.795: E/AndroidRuntime(25402):    at android.os.Looper.loop(Looper.java:130)
02-16 09:44:43.795: E/AndroidRuntime(25402):    at android.app.ActivityThread.main(ActivityThread.java:3691)
02-16 09:44:43.795: E/AndroidRuntime(25402):    at java.lang.reflect.Method.invokeNative(Native Method)
02-16 09:44:43.795: E/AndroidRuntime(25402):    at java.lang.reflect.Method.invoke(Method.java:507)
02-16 09:44:43.795: E/AndroidRuntime(25402):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
02-16 09:44:43.795: E/AndroidRuntime(25402):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
02-16 09:44:43.795: E/AndroidRuntime(25402):    at dalvik.system.NativeStart.main(Native Method)

这使我不知道,如果该.jar我引用在我的Andr​​oid库项目被正确部署......我从BIXOLON的样本项目,该项目包括直接的.jar文件(同样,我引用在我的Andr​​oid库项目),并能正常工作。我已经确信的是我自己的Andr​​oid项目,我的Andr​​oid库项目相同的(因为它是由BIXOLON提供的样本项目中定义)。所以,我有点在现在以这个问题可能是一个损失。不幸的是我没有这方面的参考BIXOLON SDK的.jar的源文件 - 只需将.jar

Which makes me wonder, if the .jar I am referencing in my Android Library project gets deployed correctly... I have a sample Project from Bixolon which directly includes their .jar file (same that I am referencing in my Android Library project) and it works fine. I already made sure the is the same in my own Android Project AND my Android Library Project (as it is defined in the sample Project provided by Bixolon). So I am a bit at a loss now as to what the problem could be. Unfortunately I don't have the source files of that referenced Bixolon SDK .jar - just the .jar.

推荐答案

查看官方开发指南的这里

库项目可以包括JAR库
  你可以开发一个库项目,本身包括JAR库,但您需要手动编辑相关的应用程序项目的构建路径,添加的路径JAR文件。

A library project can include a JAR library
You can develop a library project that itself includes a JAR library, however you need to manually edit the dependent application project's build path and add a path to the JAR file.

除了库项目,则需要手动将jar添加到您的主项目的构建路径为好,希望这种帮助。

Besides the library project, you need manually add the jar to your main project build path as well, hope this help.

从SDK R17更新:

这是自动ADT处理现在,检查出新功能的ADT 17.0.0版本的这里

This is automatically handled by ADT now, check out new feature for ADT 17.0.0 release here:

新增功能自动安装JAR依赖。在/ libs文件夹中所有.jar文件添加到构建配置(类似于Ant构建系统的工作原理)。此外,需要的库项目.jar文件也会被自动添加到依赖这些库项目的项目。 (更多信息

Added feature to automatically setup JAR dependencies. Any .jar files in the /libs folder are added to the build configuration (similar to how the Ant build system works). Also, .jar files needed by library projects are also automatically added to projects that depend on those library projects. (more info)

这篇关于Java库在通过Android项目引用一个Android库抛出NoClassDefFound的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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