2015-10-14 40 views
1

我遇到了一個令人討厭的問題。在我的項目中,我有一個庫(.aar)文件,其中包含一個appcompat-v7兼容庫。現在在我的項目,我也有下gradle.build(應用程序)文件的依賴關係部的另一程序兼容性-V7 ..Android中的Appcompat-v7衝突

問題是,當我運行的應用程序,它拋出一個異常說

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

這裏是我的應用程序gradle.build(應用程序)文件的相關部分(我是這麼認爲的)

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(應用程序)文件的相關部分(我是這麼認爲的)

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工作室..我知道這個問題已被問及之前,我已經嘗試過所有可能的解決方案。可悲的是,他們沒有幫助......請幫我

回答

1

添加下面的代碼到你的gradle產出:

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

     // Enabling multidex support. 
     multiDexEnabled true 
    } 

添加下面的依賴,增加的HttpCore和HttpClient的還。

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

對於下面的鏈接瞭解更多信息檢查:

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

謝謝..!

0

從外部級的build.gradle文件(最上面的一個)移除

compile 'com.android.support:appcompat-v7:22.2.1' 

你只需要在您的項目級的build.gradle文件。

+0

我沒有在我的項目級別的build.gradle文件..第一個是應用程序build.gradle(應用程序)文件,最下面是自定義庫build.gradle文件...你可以更具體請嗎? –

+0

你有兩個build.gradle文件,一個在你的app目錄中,另一個在你項目的根目錄下。您希望將appcompat依賴項放在應用程序中,而不是根目錄。錯誤是說你指定了兩次。 – vguzzi