Android工程方法數超過65535的解決辦法

來源:互聯網
上載者:User

標籤:aspectj   tran   應用   common   exe   class   des   ror   xxx   

  • Error:Execution failed for task ‘:ttt:transformClassesWithDexForDebug‘.
    com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536

    很不幸,今天被我遇到了,整合了一個Udesk客服功能,匯入它的moudle,裡面亂七八糟匯入了一大堆第三方。作為一個第三方客服,你這樣真的好嗎?

解決方案
  1. Gradle 配置:app的build.gradle中

      android {        defaultConfig {        applicationId "com.xxx.xxx"        minSdkVersion 14        targetSdkVersion 21        multiDexEnabled true  //加上這句話       }    }
  2. Gradle 配置:app的build.gradle中

      dependencies {        compile ‘com.android.support:multidex:1.0.1‘    }
  3. 自己的Application 類重寫方法:

      @Override                             protected void attachBaseContext(Context base) {        super.attachBaseContext(base);        MultiDex.install(this);    }

    也可以繼承android.support.multidex.MultiDexApplication類,不用重寫上面方法

  4. 如果你的應用中包含引用的lirary工程或moudle,需要將先行編譯設定為false:

     android {        // ...        dexOptions {            preDexLibraries = false        }   }
  5. 當運行時如果看到如下錯誤:

    UNEXPECTED TOP-LEVEL ERROR:
    java.lang.OutOfMemoryError: Java heap space

    在dexOptions中有一個欄位用來增加java堆記憶體大小:

      android {        // ...        dexOptions {            javaMaxHeapSize "2g"        }    }

Android工程方法數超過65535的解決辦法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.