flutter迁移androidx

作者: zengde 分类: android 发布时间: 2019-09-05 08:44

First make sure that compileSdkVersion is at least 28 in app/build.gradle. This property controls the version of the Android SDK that Gradle uses to build your APK. It doesn’t affect the minimum SDK version that your app can run on. See the Android developer docs on the module-level build file for more information.

This requires the latest version of Android Studio. Use the following instructions:

  1. 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.
  2. Follow the instructions for Migrating to AndroidX.

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.

  1. In android/gradle/wrapper/gradle-wrapper.properties change the line starting with distributionUrl like this:

    distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
    
  2. In android/build.gradle, replace:

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

    by

    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.0'
    }
    
  3. In android/gradle.properties, append

    android.enableJetifier=true
    android.useAndroidX=true
    
  4. In android/app/build.gradle:

    Under android {, make sure compileSdkVersion and targetSdkVersion are at least 28.

  5. Replace all deprecated libraries with the AndroidX equivalents. For instance, if you’re using the default .gradle files make the following changes:

    In android/app/build.gradle

    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    

    by

    testInstrumentationRunner "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'
    

    by

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

Avoiding AndroidX

原文:https://flutter.dev/docs/development/packages-and-plugins/androidx-compatibility