如何處理 android 方法總數超過 65536 . the number of method references in a .dex file exceed 64k,android.dex

來源:互聯網
上載者:User

如何處理 android 方法總數超過 65536 . the number of method references in a .dex file exceed 64k,android.dex
一:問題描述:

    應用中的Dex 檔案方法數超過了最大值65536的上限,簡單來說,應用爆棚了.

 

二、解決方案:

     方案1:使用外掛程式化架構  比如: https://github.com/singwhatiwanna/dynamic-load-apk

    方案2:分割Dex

 

三:分割 Dex 檔案實現方法 

     1、相關連結

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

     2、在app的 build.gradle 中

         (1)在dependencies 中添加  

                compile 'com.android.support:multidex:1.0.0'

         (2)在 defaultConfig 中添加

                multiDexEnabled true

                     比如   

1  defaultConfig {2         applicationId "com.pegasus.map"3         minSdkVersion 154         targetSdkVersion 235         versionCode 16         versionName "1.0"7         signingConfig signingConfigs.config8         multiDexEnabled true9     }

         (3)在 AndroidManifest.xml 中的  application 標籤中添加             

1 <?xml version="1.0" encoding="utf-8"?>2 <manifest xmlns:android="http://schemas.android.com/apk/res/android"3     package="com.example.android.multidex.myapplication">4     <application5         ...6         android:name="android.support.multidex.MultiDexApplication">7         ...8     </application>9 </manifest>

   提示:如果你的應用程式繼承 Application , 那麼你需要重寫     

1 @Override2     protected void attachBaseContext(Context base) {3         super.attachBaseContext(base);4         MultiDex.install(this) ;5     }

 

另外我的公眾帳號是: zhaoyanjun125  

我會經常發一些我的些項目的感悟和編程技術。歡迎關注。

 掃描二維碼 關注我

  

 

 

 

 

        

 

聯繫我們

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