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'

重新运行就可以了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章