Multidex issue with Flutter

前端 未结 7 1058
青春惊慌失措
青春惊慌失措 2020-11-27 17:35

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         


        
相关标签:
7条回答
  • 2020-11-27 18:12

    If you don't have experience with developing android application this information can be helpful otherwise you won't find anything new.


    How to enable multidex for flutter project.

    1. Enable multidex.

    Open project/app/build.gradle and add following lines.

    defaultConfig {
        ...
    
        multiDexEnabled true
    }
    

    and

    dependencies {
        ...
    
        implementation 'com.android.support:multidex:1.0.3'
    }
    
    1. Enable Jetifier.

    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.




    3) **Create custom application class.**

    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);
            }
    
        }
    
    1. Change the default application file to new.

    Open project/android/app/src/main/AndroidManifest.xml

    Change android:name="io.flutter.app.FlutterApplication" to android:name=".App"

    0 讨论(0)
提交回复
热议问题