本文介绍了Android Studio 中库的 NoClassDefFoundError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了几个小时试图在 Android Studio 中为我的项目创建一个库,但我就是想不通.

这是我的模块的依赖项的样子

还有我的图书馆:

我什至添加了

编译文件('libs/signpost-commonshttp4-1.2.1.2.jar')编译文件('libs/signpost-core-1.2.1.2.jar')

到我的 build.gradle.没有这个,应用程序甚至无法编译.

在此阶段,当我尝试在代码中引用其中一个库时,应用程序崩溃并出现 NoClassDefFoundError 异常.

有人告诉我这不应该这么难 - 我忽略了什么?

LogCat:

05-17 21:51:15.676: I/ActivityManager(714): START u0 {flg=0x10104000 cmp=com.crazydog.splitwiser/.InitialSplash bnds=[328,402][656,6915]} from05-17 21:51:15.896: I/ActivityManager(714): 为活动 com.crazydog.splitwiser/.InitialSplash 启动 proc com.crazydog.splitwiser: pid=18174 uid=10288 gids={50288, 3203}, 1005-17 21:51:16.326: I/ActivityManager(714): 显示 com.crazydog.splitwiser/.InitialSplash: +437ms (total +1m9s209ms)05-17 21:51:17.017:I/ActivityManager(714):从 pid 18174 开始 u0 {cmp=com.crazydog.splitwiser/.LogIn}05-17 21:51:17.097: E/dalvikvm(18174): 找不到类 'oauth.signpost.commonshttp.CommonsHttpOAuthConsumer',从方法 com.crazydog.splitwiser.Toolkit.oAuthTransaction 引用05-17 21:51:17.097: W/dalvikvm(18174): VFY: 无法解析 Lcom/crazydog/splitwiser/Toolkit 中的新实例 662 (Loauth/signpost/commonshttp/CommonsHttpOAuthConsumer;);05-17 21:51:17.097:D/dalvikvm(18174):DexOpt:无法选择在 Lcom/crazydog/splitwiser/Toolkit 中的 0x08 处直接调用 0x112f;.oAuthTransaction05-17 21:51:17.107: E/AndroidRuntime(18174): 在 com.crazydog.splitwiser.Toolkit.oAuthTransaction(Toolkit.java:65)05-17 21:51:17.107: E/AndroidRuntime(18174): 在 com.crazydog.splitwiser.LogIn.onResume(LogIn.java:116)05-17 21:51:17.117:W/ActivityManager(714):强制完成活动 com.crazydog.splitwiser/.LogIn05-17 21:51:17.117:W/ActivityManager(714):强制完成活动 com.crazydog.splitwiser/.InitialSplash05-17 21:51:17.618:W/ActivityManager(714):ActivityRecord 的活动暂停超时{40d040d0 u0 com.crazydog.splitwiser/.LogIn}
解决方案

我遇到了完全相同的问题,和你一样,我认为添加

就足够了

编译文件('libs/signpost-commonshttp4-1.2.1.2.jar')编译文件('libs/signpost-core-1.2.1.2.jar')

在我做了一个 ./gradlew clean 之后一切都奏效了(我使用的是 mac,所以在你的情况下,等价的.)当您位于项目的根目录时,您应该从终端/命令提示符执行此命令.

I've spent hours trying to get a library to work with my project in Android Studio, and I just can't figure it out.

Here's what my dependencies look like for my module

And my libraries:

I've even added

to my build.gradle. Without this, the app would not even compile.

At this stage, when I try to reference one of the libraries in code, the app crashes with a NoClassDefFoundError exception.

Something tells me this shouldn't be this hard - what am I overlooking?

LogCat:

05-17 21:51:15.676: I/ActivityManager(714): START u0 {flg=0x10104000 cmp=com.crazydog.splitwiser/.InitialSplash bnds=[328,402][656,692]} from pid 1513
05-17 21:51:15.896: I/ActivityManager(714): Start proc com.crazydog.splitwiser for activity com.crazydog.splitwiser/.InitialSplash: pid=18174 uid=10288 gids={50288, 3003, 1028}
05-17 21:51:16.326: I/ActivityManager(714): Displayed com.crazydog.splitwiser/.InitialSplash: +437ms (total +1m9s209ms)
05-17 21:51:17.017: I/ActivityManager(714): START u0 {cmp=com.crazydog.splitwiser/.LogIn} from pid 18174
05-17 21:51:17.097: E/dalvikvm(18174): Could not find class 'oauth.signpost.commonshttp.CommonsHttpOAuthConsumer', referenced from method com.crazydog.splitwiser.Toolkit.oAuthTransaction
05-17 21:51:17.097: W/dalvikvm(18174): VFY: unable to resolve new-instance 662 (Loauth/signpost/commonshttp/CommonsHttpOAuthConsumer;) in Lcom/crazydog/splitwiser/Toolkit;
05-17 21:51:17.097: D/dalvikvm(18174): DexOpt: unable to opt direct call 0x112f at 0x08 in Lcom/crazydog/splitwiser/Toolkit;.oAuthTransaction
05-17 21:51:17.107: E/AndroidRuntime(18174):    at com.crazydog.splitwiser.Toolkit.oAuthTransaction(Toolkit.java:65)
05-17 21:51:17.107: E/AndroidRuntime(18174):    at com.crazydog.splitwiser.LogIn.onResume(LogIn.java:116)
05-17 21:51:17.117: W/ActivityManager(714):   Force finishing activity com.crazydog.splitwiser/.LogIn
05-17 21:51:17.117: W/ActivityManager(714):   Force finishing activity com.crazydog.splitwiser/.InitialSplash
05-17 21:51:17.618: W/ActivityManager(714): Activity pause timeout for ActivityRecord{40d040d0 u0 com.crazydog.splitwiser/.LogIn}
解决方案

I had the exact same problem,And like you i thought it's enough to add the

compile files('libs/signpost-commonshttp4-1.2.1.2.jar')
compile files('libs/signpost-core-1.2.1.2.jar')

It all worked after i did a ./gradlew clean (I'm on a mac, so in your case, the equivalent.)You should do this command from the Terminal/Command prompt when you're located on the root of your project.

这篇关于Android Studio 中库的 NoClassDefFoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-27 09:38