Multidex issue with Flutter

断了今生、忘了曾经 提交于 2019-11-27 04:40:40
Mikkel Ravn

Your two packages seem to disagree on their transitive dependencies. One wants 11.6.+, the other wants 11.+ of some play-services dependencies. Since both 11.6.2 and 11.8.0 are out there, this is going to end up with a conflict.

If you run ./gradlew androidDependencies in your android/ folder, you get a listing of the result of dependency resolution, containing, among others, the following:

+--- :flutter_google_place_picker (variant: release)
+--- com.google.android.gms:play-services-location:11.8.0@aar
+--- com.google.android.gms:play-services-places:11.6.2@aar
+--- com.google.android.gms:play-services-maps:11.6.2@aar
+--- com.google.android.gms:play-services-base:11.8.0@aar
+--- com.google.android.gms:play-services-tasks:11.8.0@aar
+--- com.google.android.gms:play-services-basement:11.8.0@aar

These 11.6.2 and 11.8.0 packages are not going to work together. To resolve this, you need to patch your dependencies to be consistent with each other, or add a dependency override to the top level of your android/app/build.gradle file and hope for the best:

configurations.all {
    resolutionStrategy {
        force 'com.google.android.gms:play-services-places:11.8.0'
        force 'com.google.android.gms:play-services-location:11.8.0'
    }
}

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'
}

2) Enable Jetifier.

Open project/android/app/gradle.properties and add following lines.

android.useAndroidX=true
android.enableJetifier=true

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);
    }

}

4) 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"

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!