Android: my application is too large and gives “Unable to execute dex: method ID not in [0, 0xffff]: 65536”?

前端 未结 8 1985
慢半拍i
慢半拍i 2020-11-27 04:52

I am trying to integrate my application with Box, Dropbox, and Google Drive. All 3 of these services require a number of 3rd party jars. Additionally, my application alrea

8条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-27 05:07

    You need to enable the Dex support for that. So you need to do these steps:

    1. Gradle plugin v0.14.0 for Android adds support for multi-dex. To enable, you just have to declare it in build.gradle:
    android {
       defaultConfig {
          ...
          multiDexEnabled = true
       }
    }
    
    1. if app support > 5.0 (that is, if your minSdkVersion is 20 or below) you also have to dynamically patch the application ClassLoader, so it will be able to load classes from secondary dexes. for that you can add this lib.
     dependencies {
          ...
          compile 'com.android.support:multidex:1.0.0'
        }
    
    1. enable in code for that you have these option. choose one which suits you best

    A. Add MultiDexApplication in manifest manifest

     
    
    
    

    B. Extend the application by MultiDexApplication

    public class App extends MultiDexApplication { .. }
    

    C. install it in application in attaching base context.

    public class App {
        protected void attachBaseContext(Context base) {
            super.attachBaseContext(base);
            MultiDex.install(this);
            ..
        }
    
    }
    

    For more go through this link MultiDex.

提交回复
热议问题