Flutter AndroidX冲突解决

新项目准备用Flutter开发,把所有的东西都更新以后,运行项目发现报了AndroidX和support冲突的问题。

决绝办法有两种:

一、将 compileSdkVersion 版本号降低到28以下。使用support版本

在这里插入图片描述

二、使用AndroidX版本

官方链接:https://flutter.dev/docs/development/packages-and-plugins/androidx-compatibility

1、修改gradle-wrapper依赖

位置为:android/gradle/wrapper/gradle-wrapper.properties
修改为:

distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip

2、修改android/build.gradle版本号

dependencies {
    classpath 'com.android.tools.build:gradle:3.3.0'
}

3、添加AndroidX支持

android/gradle.properties路径下添加:

android.enableJetifier=true
android.useAndroidX=true

4、确保compileSdkVersion 和 targetSdkVersion >= 28

AndroidX支持最低版本28

5、添加AndroidX依赖

android/app/build.gradle路径下
1、把testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"改为testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

2、将support改为androidx

androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

改为

androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'

重新运行就可以了。

发布了82 篇原创文章 · 获赞 16 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/sjdjdjdjahd/article/details/101063940