Android Studio:Multiple dex files define Landroid/support/annotation/AnimRes

來源:互聯網
上載者:User

標籤:port   compile   this   pretty   net   java   pos   UI   pre   

近期真的比較忙,一不小心部落格又荒了兩個月。

從今天起,決定重返csdn,多多紀錄和分享。

先從一個近期被折磨的死去活來的問題。
由於升級了V4包。就一直報這個問題:

com.android.dex.DexException: Multiple dex files define Landroid/support/annotation/AnimRes;

每次都要clean一下,然後才幹編譯過。光這個過程就浪費了4/5分鐘。出現這個問題是由於最新的v4包(compile ‘com.android.support:support-v4:22.2.1’)已經包括了annotation.jar這個包,但其它jar包裡也包括這個包造成的。而非同一時候包括了v4/V7造成的,所以一堆人說在v7包裡進行例如以下設定:

compile (‘com.android.support:appcompat-v7:22.2.1‘){        exclude group: "com.android.support", module: "support-v4"    }

即設定v7包不包括v4,這個設了也是無用的。

僅僅要確保用v4和v7 的地方版本號碼一致就可以。

正確的解決方案有例如以下幾種:
1,找到項目其它的依賴包。一定在libs裡的某個jar包裡。隱藏著annotation.jar包,將其刪掉就ok了。此為最正統的解決方案。
2,降級v4包。由於高版本號碼的v4才包括annotation.jar,能夠在最外面的build.grable裡強制設定:

allprojects {    repositories {        jcenter()    }    configurations.all {        resolutionStrategy.force ‘com.android.support:support-annotations:22.1.0‘    }}

3,在須要v4包的地方exclude掉annotation包。注意compile要多加個括弧:

 compile (‘com.android.support:support-v4:22.2.1‘){        exclude module: ‘support-annotations‘    }

缺點是每一個用v4包的地方都要這麼設定下。
4。在application的build.gradle裡的dexOptions設定裡添加一句:preDexLibraries = false就ok了:

PS:以上四種方法都能夠解決這個問題,推薦正統的方法1和偷懶的方法4。

Android Studio:Multiple dex files define Landroid/support/annotation/AnimRes

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.