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

问题描述

我遇到了一个令人讨厌的问题.在我的项目中,我有一个库(.aar)文件,其中包含一个appcompat-v7兼容性库.现在在我的项目中,在gradle.build(应用程序)文件的依赖项下,我还有另一个appcompat-v7.

I ran into a nasty problem. In my project I have a library (.aar) file which is including an appcompat-v7 compatibility library. Now in my project I also have another appcompat-v7 under the dependency section of gradle.build (app) file..

问题是,当我运行应用程序时,它会抛出一个异常提示

The problem is when I run the Application it throws an exception saying

UNEXPECTED TOP-LEVEL EXCEPTION:com.android.dex.DexException: Multiple dex files define Landroid/support/v7/appcompat/R$anim;

这是我的应用程序gradle.build(应用程序)文件的相关部分(我认为是这样)

Here is my application gradle.build (app) file relevant part (I think so)

repositories {
      flatDir {
        dirs 'libs'
      }
}

dependencies {
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:22.2.1'
    compile(name: 'conversityChat-debug', ext: 'aar') {
        exclude group: 'com.android.support', module: 'support-v7'
    }
}

这是我的图书馆gradle.build(app)文件的相关部分(我认为是这样)

And here is my library gradle.build(app) file relevant part (I think so)

dependencies {
compile project(':androidwebsocketsmaster')
compile 'com.android.support:appcompat-v7:22.2.1'
compile files('libs/acra-4.5.0.jar')
compile files('libs/universal-image-loader-1.9.4.jar')
}

我正在使用android studio..我知道之前已经有人问过这个问题,并且我已经尝试了所有建议的可能解决方案.不幸的是,他们都没有帮助...请帮助我

I'm using android studio.. I know this question has been asked before, and I've tried out all possible solutions suggested over there. Sadly, None of them helped... Please help me out

推荐答案

将以下代码添加到gradle中:

Add below code to your gradle :

defaultConfig {
        ...
        minSdkVersion 14
        targetSdkVersion 21
        ...

        // Enabling multidex support.
        multiDexEnabled true
    }

添加以下依赖项,并同时添加HttpCore和HttpClient.

Add below dependency and add HttpCore and HttpClient also.

dependencies {
  compile 'com.android.support:multidex:1.0.0'
}

有关更多信息,请参见下面的链接:

For more information check below link :

https://developer.android.com/tools/building/multidex.html

谢谢.. !!

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

08-18 20:37