I\'m getting the following error compiling with gradle using Flutter in Android Studio:
Dex: Error converting bytecode to dex:
Cause: com.android.dex.DexExce
How to enable multidex for flutter project.
Open project/app/build.gradle
and add following lines.
defaultConfig {
...
multiDexEnabled true
}
and
dependencies {
...
implementation 'com.android.support:multidex:1.0.3'
}
Open project/android/app/gradle.properties
and add following lines.
android.useAndroidX=true
android.enableJetifier=true
NOTE: As of flutter 1.7, the below steps are no longer necessary.
If you don't know where to create the file do it near MainActivity
for example project/android/app/src/main/kotlin(or java if you didn't enable kotlin)/your/great/pakage/appname/
kotlin example: App.kt
package your.great.pakage.appname
import io.flutter.app.FlutterApplication
import android.content.Context
import androidx.multidex.MultiDex
class App : FlutterApplication() {
override fun attachBaseContext(base: Context) {
super.attachBaseContext(base)
MultiDex.install(this)
}
}
java example: App.java
package your.great.pakage.appname;
import io.flutter.app.FlutterApplication;
import android.content.Context;
import androidx.multidex.MultiDex;
public class App extends FlutterApplication {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
Open project/android/app/src/main/AndroidManifest.xml
Change android:name="io.flutter.app.FlutterApplication"
to android:name=".App"