我正在尝试将 ZXing 包含在我的 Android 应用程序中。
由于 ZXing 只提供 java 源代码,所以我自己创建了 jar 文件。
接下来,我通过将 JAR 拖到 Eclipse 中我的 Android 项目的 libs 文件夹中来添加它。
项目浏览器看起来像这样
构建路径如下所示
在我自己的代码中,我尝试从该 JAR 实例化一个类:
IntentIntegratorV30 integrator = new IntentIntegratorV30(this);
编译时没有错误。
但是在真实设备上运行时出现以下错误:
06-09 21:06:32.050: E/AndroidRuntime(1656): java.lang.NoClassDefFoundError: com.google.zxing.integration.android.IntentIntegratorV30
完整的 LogCat 是:
06-09 21:06:32.010: I/ApplicationPackageManager(1656): cscCountry is not German : XEO
06-09 21:06:32.010: I/dalvikvm(1656): Could not find method com.google.zxing.integration.android.IntentIntegratorV30.parseActivityResult, referenced from method de.fzi.guideme.fragments.scanner.ScannerFragment.onActivityResult
06-09 21:06:32.010: W/dalvikvm(1656): VFY: unable to resolve static method 181: Lcom/google/zxing/integration/android/IntentIntegratorV30;.parseActivityResult (IILandroid/content/Intent;)Lcom/google/zxing/integration/android/IntentResult;
06-09 21:06:32.010: D/dalvikvm(1656): VFY: replacing opcode 0x71 at 0x0003
06-09 21:06:32.020: E/dalvikvm(1656): Could not find class 'com.google.zxing.integration.android.IntentIntegratorV30', referenced from method de.fzi.guideme.fragments.scanner.ScannerFragment.onCreateView
06-09 21:06:32.020: W/dalvikvm(1656): VFY: unable to resolve new-instance 67 (Lcom/google/zxing/integration/android/IntentIntegratorV30;) in Lde/fzi/guideme/fragments/scanner/ScannerFragment;
06-09 21:06:32.020: D/dalvikvm(1656): VFY: replacing opcode 0x22 at 0x002d
06-09 21:06:32.020: I/GuideMe(1656): Fragment: class de.fzi.guideme.fragments.scanner.ScannerFragment, manual: null, function: null, step: null
06-09 21:06:32.040: D/AndroidRuntime(1656): Shutting down VM
06-09 21:06:32.040: W/dalvikvm(1656): threadid=1: thread exiting with uncaught exception (group=0x401d2760)
06-09 21:06:32.050: E/AndroidRuntime(1656): FATAL EXCEPTION: main
06-09 21:06:32.050: E/AndroidRuntime(1656): java.lang.NoClassDefFoundError: com.google.zxing.integration.android.IntentIntegratorV30
06-09 21:06:32.050: E/AndroidRuntime(1656): at de.fzi.guideme.fragments.scanner.ScannerFragment.onCreateView(ScannerFragment.java:47)
06-09 21:06:32.050: E/AndroidRuntime(1656): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:735)
06-09 21:06:32.050: E/AndroidRuntime(1656): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:926)
06-09 21:06:32.050: E/AndroidRuntime(1656): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:909)
06-09 21:06:32.050: E/AndroidRuntime(1656): at android.app.FragmentManagerImpl.dispatchStart(FragmentManager.java:1584)
06-09 21:06:32.050: E/AndroidRuntime(1656): at android.app.Activity.performStart(Activity.java:4377)
06-09 21:06:32.050: E/AndroidRuntime(1656): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1724)
06-09 21:06:32.050: E/AndroidRuntime(1656): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1767)
06-09 21:06:32.050: E/AndroidRuntime(1656): at android.app.ActivityThread.access$1500(ActivityThread.java:122)
06-09 21:06:32.050: E/AndroidRuntime(1656): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1005)
06-09 21:06:32.050: E/AndroidRuntime(1656): at android.os.Handler.dispatchMessage(Handler.java:99)
06-09 21:06:32.050: E/AndroidRuntime(1656): at android.os.Looper.loop(Looper.java:132)
06-09 21:06:32.050: E/AndroidRuntime(1656): at android.app.ActivityThread.main(ActivityThread.java:4028)
06-09 21:06:32.050: E/AndroidRuntime(1656): at java.lang.reflect.Method.invokeNative(Native Method)
06-09 21:06:32.050: E/AndroidRuntime(1656): at java.lang.reflect.Method.invoke(Method.java:491)
06-09 21:06:32.050: E/AndroidRuntime(1656): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
06-09 21:06:32.050: E/AndroidRuntime(1656): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
06-09 21:06:32.050: E/AndroidRuntime(1656): at dalvik.system.NativeStart.main(Native Method)
我使用带有 Android SDK Tools Rev. 19 的 Eclipse 3.7.2 和运行 Android 3.1 的三星 Galaxy Tab 10.1。
看起来 JAR 没有包含在 APK 文件中。有关如何解决此问题的任何建议?
编辑:回答我自己的问题(作为评论中讨论的结果)。我试图包含的 JAR 一定是错误的。正确构建 JAR 将在别处讨论。