Flutter开发:迁移Flutter应用到AndroidX
首先上官方文档:https://flutter.dev/docs/development/packages-and-plugins/androidx-compatibility
有两种方式,一种由Android studio自动完成,一种手动修改依赖配置。 官方推荐第一种,不过在我这不好使,于是我用了第二种,也成功跑起来了~
自动方式
Use Android Studio to migrate your app
This requires the latest version of Android Studio. Use the following instructions:
- Import your Flutter app into Android Studio so that the IDE can parse the Android code following the steps in Editing Android code in Android Studio with full IDE support.
- Follow the instructions for Migrating to AndroidX.
手动方式
Manually migrate your app
See Migrating to AndroidX for more detailed instructions on how to do this. Below are some steps that you’ll likely need to go through as part of this process, listed here for reference. However the specific things you need to do will depend on your build configuration and could differ from the example changes suggested here.
-
In
android/gradle/wrapper/gradle-wrapper.properties
change the line starting withdistributionUrl
like this:distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
-
In
android/build.gradle
, replace: content_copy
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
}
-
In
android/gradle.properties
, appendandroid.enableJetifier=true android.useAndroidX=true
-
In
android/app/build.gradle
: Underandroid {
, make surecompileSdkVersion
andtargetSdkVersion
are at least 28. -
Replace all deprecated libraries with the AndroidX equivalents. For instance, if you’re using the default
.gradle
files make the following changes: Inandroid/app/build.gradle
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
bytestInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Finally, under dependencies {
, replace
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'
欢迎交流
交流问题请在微信公众号后台留言,每一条信息我都会回复哈~ - 微信公众号:画星星高手 - 打代码直播间:https://live.bilibili.com/11883038 - 知乎:https://www.zhihu.com/people/dealiaxy - 简书:https://www.jianshu.com/u/965b95853b9f