Dpower Dpower - 6 months ago 174
Android Question

Where add 64K code and where?

What code must i add and where to get 64K methods?

I try and build signed APK but it give me issue whole time!

Error:The number of method references in a .dex file cannot exceed 64K.


Error:Execution failed for task
’:myapp:transformClassesWithDexForRelease’. >
com.android.build.api.transform.TransformException:
com.android.ide.common.process.ProcessException:
java.util.concurrent.ExecutionException:
java.lang.UnsupportedOperationException

Answer

KUMAR's answer is pretty close but not covering all the details.

Firstly add necessary configuration to your build.gradle of app module:

app/build.gradle

android {
   defaultConfig {
      multiDexEnabled true
   }
}

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

In the second step you can follow two paths depending on your need.

a. You don't have a custom application class. So you need to add the MultiDexApplication class from the multidex support library to the application element in your manifest:

AndroidManifest.xml

<application
        android:name="android.support.multidex.MultiDexApplication"

OR

b. You have a custom application class. So you need to make it extend MultiDexApplication class:

MyApplication.java

public class MyApplication extends MultiDexApplication {

}

AndroidManifest.xml

<application
    android:name="MyApplication"

You should be ready to go over 64K method limit.

You can read this tutorial over multidex to understand the logic behind all of these.

Comments