迁移到 AndroidX

备忘 You might be directed to this page if the tool detects that your project doesn’t use AndroidX.

AndroidX is a major improvementto the original Android Support Library.

It provides the androidx.* package libraries, unbundled from the platform API.This means that it offers backward compatibility and is updated more frequentlythan the Android platform.

Common Questions

How do I migrate my existing app, plugin or host-editable module project to AndroidX?

You will need Android Studio 3.2 or higher. If you don’t have it installed,you can download the latest version fromdeveloper.android.com/studio.

  • Open Android Studio.
  • Select Open an existing Android Studio Project.
  • Open the android directory within your app.
  • Wait until the project has been synced successfully. (This happens automatically once you open the project, but if it doesn’t,select Sync Project with Gradle Files from the File menu).
  • Select Migrate to AndroidX from the Refactor menu.
  • If you are asked to backup the project before proceeding,check Backup project as Zip file, then click Migrate. Lastly, savethe zip file in your location of preference. Select backup project as zip file
  • The refactoring preview shows the list of changes. Finally, click Do Refactor: An animation of the bottom-up page transition on Android
  • That is it! You successfully migrated your project to AndroidX.Finally, if you migrated a plugin, publish the new AndroidX version to pub and updateyour CHANGELOG.md to indicate that this new version is compatible with AndroidX.

What about if I can’t use Android Studio?

You can create a new project using the Flutter tool and then move the Dart code andassets to the new project.

To create a new project run:

  1. flutter create --androidx -t <project-type> <new-project-path>

Add to App

If your Flutter project is a module type for adding to an existing Android app, and contains a .android directory, add the following line to pubspec.yaml:

  1. module:
  2. ...
  3. androidX: true // Add this line.

Finally, run flutter clean.

If your module contains an android directory instead, then follow thesteps in previous section.

How do I know if my project is using AndroidX?

  • Apps and ModulesYour project uses AndroidX if the file android/gradle.properties or.android/gradle.properties contains:
  1. android.useAndroidX=true
  2. android.enableJetifier=true
  • PluginsIf a file under the android directory references any old support library packageor old support support artifacts, then the plugin isn’t using AndroidX.

What if I don’t migrate my app or module to AndroidX?

Your app may continue to work. However, combining AndroidX and Support artifactsis generally not recommended because it can result in dependency conflicts orother kind of Gradle failures. As a result, as more plugins migrate to AndroidX,plugins depending on Android core libraries are likely to cause build failures.

What if my app is migrated to AndroidX, but not all of the plugins I use?

The Flutter tool uses Jetifier to automatically migrate Flutter plugins usingthe Support Library to AndroidX, so you can use the same plugins even if theyhaven’t been migrated to AndroidX yet.

I’m having issues migrating to AndroidX

Open an issue on GitHuband add [androidx-migration] to the title of the issue.