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 module/build.gradle
:
android {
defaultConfig {
...
// Enabling multidex support.
multiDexEnabled true
}
...
}
dependencies {
implementation 'com.android.support:multidex:1.0.3' //with support libraries
//implementation 'androidx.multidex:multidex:2.0.1' //with androidx libraries
}
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 androidx use android:name="androidx.multidex.MultiDexApplication" -->
<!--If you are using your own custom Application class then extend -->
<!--MultiDexApplication and change above line as-->
<!--android:name=".YourCustomApplicationClass"> -->
...
</application>
</manifest>
If you are using your own Application
class, change the parent class from Application
to MultiDexApplication
.
If you can't do it, in your Application class override the attachBaseContext
method with:
@Override
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(newBase);
MultiDex.install(this);
}
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.