eclipse 更新 sdk 得到了 NoClassDefFoundError for zxing

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9889737/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 17:55:00  来源:igfitidea点击:

Updating sdk got NoClassDefFoundError for zxing

androideclipsezxing

提问by Kishore

How to solve this NoClassDefFoundError. I have integrated Zxing in my app, every thing is working fine. Then I have updated my sdk and eclipse plugin, and when I run the project the log says

如何解决这个 NoClassDefFoundError。我在我的应用程序中集成了 Zxing,一切正常。然后我更新了我的 sdk 和 eclipse 插件,当我运行项目时,日志说

03-27 17:27:45.173: E/AndroidRuntime(8917): FATAL EXCEPTION: main
03-27 17:27:45.173: E/AndroidRuntime(8917): java.lang.ExceptionInInitializerError
03-27 17:27:45.173: E/AndroidRuntime(8917):     at java.lang.Class.newInstanceImpl(Native Method)
03-27 17:27:45.173: E/AndroidRuntime(8917):     at java.lang.Class.newInstance(Class.java:1429)
03-27 17:27:45.173: E/AndroidRuntime(8917):     at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
03-27 17:27:45.173: E/AndroidRuntime(8917):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
03-27 17:27:45.173: E/AndroidRuntime(8917):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
03-27 17:27:45.173: E/AndroidRuntime(8917):     at android.app.ActivityThread.access00(ActivityThread.java:125)
03-27 17:27:45.173: E/AndroidRuntime(8917):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
03-27 17:27:45.173: E/AndroidRuntime(8917):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-27 17:27:45.173: E/AndroidRuntime(8917):     at android.os.Looper.loop(Looper.java:123)
03-27 17:27:45.173: E/AndroidRuntime(8917):     at android.app.ActivityThread.main(ActivityThread.java:4627)
03-27 17:27:45.173: E/AndroidRuntime(8917):     at java.lang.reflect.Method.invokeNative(Native Method)
03-27 17:27:45.173: E/AndroidRuntime(8917):     at java.lang.reflect.Method.invoke(Method.java:521)
03-27 17:27:45.173: E/AndroidRuntime(8917):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
03-27 17:27:45.173: E/AndroidRuntime(8917):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
03-27 17:27:45.173: E/AndroidRuntime(8917):     at dalvik.system.NativeStart.main(Native Method)
03-27 17:27:45.173: E/AndroidRuntime(8917): Caused by: java.lang.NoClassDefFoundError: com.google.zxing.ResultMetadataType
03-27 17:27:45.173: E/AndroidRuntime(8917):     at records.model.CaptureActivity.<clinit>(CaptureActivity.java:94)`

回答by Till

I didn't have to put the jar-library in assets or lib(s), but only tick the box for this jar in Properties -> Java Build Path -> "Order and Export" (it was listed before, but not selected)

我不必将 jar-library 放在 assets 或 lib(s) 中,而只需在 Properties -> Java Build Path -> "Order and Export" 中勾选此 jar 的框(之前已列出,但未选中) )

You might have to do a project > clean after this to take effect! (Thanks mwengler and Mohamed)

你可能需要做一个项目>清理之后才能生效!(感谢 mwengler 和 Mohamed)

回答by fly84021210

Go to Properties -> Java Build Path -> "Order and Export"

转到属性-> Java 构建路径->“订购和导出”

Then order the core.jar to the first position and select it!

然后将core.jar排序到第一个位置并选中它!

you must clean your project after your operation. Project -> clean

您必须在操作后清理您的项目。项目 -> 清洁

That will solve the problem

这将解决问题

回答by Andy Smith

You are referencing the Class com.google.zxing.ResultMetadataTypein CaptureActivity.javaon line 94but the definition for this Class cannot be found (ClassDefNotFound). If it cannot be found then it must not be on your class path.

你引用的类com.google.zxing.ResultMetadataTypeCaptureActivity.java上线94,但这个类的定义不能找到(ClassDefNotFound)。如果找不到,那么它一定不在您的类路径上。

There is probably a .jar file somewhere on your disk that contains com.google.zxing.ResultMetadataType(seemingly core.jar) place this on your project's class path to resolve this issue.

您的磁盘上可能有一个 .jar 文件,其中包含com.google.zxing.ResultMetadataType(似乎core.jar)将它放在项目的类路径上以解决此问题。

回答by John O'Connor

For some reason, ADT is no longer including libraries from your build path in the generated .apk file.

出于某种原因,ADT 不再在生成的 .apk 文件中包含来自构建路径的库。

To fix, create a "libs" folder in the root of your project (ie: bin, src, assets, libs) and put the core.jar file in there. Remove all other instances from your build path, and everything should work fine.

要修复,请在项目的根目录(即:bin、src、assets、libs)中创建一个“libs”文件夹,并将 core.jar 文件放在那里。从构建路径中删除所有其他实例,一切都应该正常工作。

NoClassDefFoundError - Eclipse and Android

NoClassDefFoundError - Eclipse 和 Android

回答by jhilden

This worked for me (after about 8 hours of messing around). The key is that you need to create the libs folder in the CaptureClientproject, drop in core.jar, then add a reference to core.jar.

这对我有用(经过大约 8 小时的混乱)。关键是需要在CaptureClient项目中创建libs文件夹,放入core.jar,然后添加对core.jar的引用。

Then from your project, reference the CaptureClient project.

然后从您的项目中,引用 CaptureClient 项目。

Wow, that was about a million times harder than it should have been!

哇,这比应该的困难大约一百万倍!

https://stackoverflow.com/a/2248017/1173800

https://stackoverflow.com/a/2248017/1173800

回答by Cullan

I had the same thing happen to me with a different .jar also after upgrading SDK and plugin.

升级 SDK 和插件后,我也用不同的 .jar 发生了同样的事情。

Andrews answer below with link stackoverflow.com/a/2248017/180295with points 3 and 4 worked for me.

安德鲁斯回答下面的链接stackoverflow.com/a/2248017/180295,第 3 点和第 4 点对我有用。

回答by Sean Owen

It means exactly what it says. You are using library code that you did not actually include into your app. Make sure the the contents of core.jarfrom the project are part of your project, as a library project.

这正是它所说的意思。您使用的库代码实际上并未包含在您的应用程序中。确保core.jar项目中的内容是您项目的一部分,作为库项目。

回答by Julian Cerruti

I had the same issue but was using the new Gradle build and Adroid Studio.

我有同样的问题,但使用的是新的 Gradle 版本和 Adroid Studio。

What solved it for me was to go outside of Android Studio and do a clean and build from the command-line using gradle:

为我解决的是走出 Android Studio 并使用 gradle 从命令行进行清理和构建:

gradle clean
gradle assembleDebug 

and the NoClassDefFound exception magically went away

并且 NoClassDefFound 异常神奇地消失了

回答by Zain Ali

In my case the problem was with Android Build Tools I had version 18 but need to have Android Build Tools version 19 or later because I need to have my eclipse JDK compliance to 1.7 instead of 1.6 as CORE.JAR using Java version 1.7.

在我的情况下,问题出在 Android 构建工具上,我有 18 版,但需要有 19 版或更高版本的 Android 构建工具,因为我需要使我的 Eclipse JDK 符合 1.7 而不是 1.6 作为使用 Java 1.7 版的 CORE.JAR。

I would also suggest to look at the messages in android console during build process it will give you idea of exact problem.

我还建议在构建过程中查看 android 控制台中的消息,它会让您了解确切的问题。

回答by kunal

Add the core.jar to libs folder of your android project and don't add it as an external jar in java build path.

将 core.jar 添加到您的 android 项目的 libs 文件夹中,不要将其添加为 java 构建路径中的外部 jar。