Android Studio:解决重复的类 [英] Android Studio: Resolving Duplicate Classes

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

问题描述

当我尝试在Android设备上run我的android应用程序时,gradle控制台报告以下错误:

When I try to run my android application on an Android device, the gradle console reports the following error:

Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/loopj/android/http/AsyncHttpClient$1.class

当我搜索"AsyncHttpClient"类时,我发现确实在两个单独的位置找到了它:

When I search for the "AsyncHttpClient" class, I see that it's indeed being found in two separate locations:

/Users/Afflatus/.gradle/caches/modules-2/files-2.1/com.loopj.android/android-async-http/1.4.9/5d171c3cd5343e5997f974561abed21442273fd1/android-async-http-1.4.9-sources.jar!/com/loopj/android/http/AsyncHttpClient.java

/Users/Afflatus/.ideaLibSources/android-async-http-1.4.9-sources.jar!/com/loopj/android/http/AsyncHttpClient.java

第一个路径似乎表明它是一个缓存"文件...所以我尝试了invalidating & restarting my cache,但是在重新构建gradle之后,两个文件仍然存在,我尝试run该应用程序.我已经阅读了其他帖子,可以通过删除其中一个文件来解决...所以我去了缓存位置,删除了在"1.4.9"文件夹中找到的所有文件...不幸的是,在重新打开Android Studio之后,创建了一个新的缓存文件,并且遇到了同样的错误.

The first path seems to suggest it's a "cache" file... so I've tried invalidating & restarting my cache, but both files are still there after the gradle gets rebuilt and I try to run the application. I've read in alternate posts that it can be resolved by deleting one of the files... So I went to the cache location and deleted all the files found in the "1.4.9" folder... unfortunantly after reopening Android Studio, a new cache file gets created and I get the same error.

其他帖子(此处此处,以及此处)建议我是否添加"./gradlew clean"到根目录,它将再次为运行重新构建gradle(据我了解).所以我也尝试这样做:

Other posts (here, here,here, and here) suggest if I add "./gradlew clean" to the root directory it would rebuild the gradle again just for the run (as far as I understand). So I tried doing that as well:

这使我的应用程序的文件夹看起来像这样:

Which made my app's folder look like this:

但是不幸的是,这仍然无济于事,我仍然遇到相同的错误.我究竟做错了什么?我该怎么办?

But unfortunantly, that didn't help things I still get the same error. What am I doing wrong? What should I be doing?

推荐答案

它是因为您在libs文件夹中两次添加了一些库,所以当您在libs文件夹中具有相同库的多个版本时,有时可能会发生这种情况.检查并删除所有重复的jar文件.

its because you have added some Library two times in libs folder, this could happen sometimes when you have multiple versions of same library in libs folder. Check it and remove any duplicate jar file.

和第二个选项可能是您还在gradle.build中添加了依赖项,并且在libs文件夹中也有jar.

and second option could be you have also added the dependency in gradle.build and also have jar in libs folder.

因此,检查两个地方并删除重复的条目,然后再次清理并构建APK.

So check both places and remove duplicate entries and the clean and build APK again.

希望有帮助

这篇关于Android Studio:解决重复的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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