You have too many methods. There can only be 65536 methods for dex.
As suggested you can use the multidex support.
Just add these lines in the build.gradle
:
android {
defaultConfig {
...
// Enabling multidex support.
multiDexEnabled true
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
Also in your Manifest
add the MultiDexApplication
class from the multidex support library to the application element
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.multidex.myapplication">
<application
...
android:name="android.support.multidex.MultiDexApplication">
<!--If you are using your own custom Application class then extend -->
<!--MultiDexApplication and change above line as-->
android:name=".YourCustomApplicationClass">
...
</application>
</manifest>
override attachBaseContext method
@Override
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(newBase);
MultiDex.install(this);
}
If you are using your own Application
class, change the parent class from Application
to MultiDexApplication
.
Another solution is to try to remove unused code with ProGuard - Configure the ProGuard settings for your app to run ProGuard and ensure you have shrinking enabled for release builds.