- Migrating to AndroidX / Переход на AndroidX
- Перевод Flutter приложения на AndroidX в автоматическом режиме с помощью Android Studio
- AndroidX Migration
- Common Questions
- How do I migrate my existing app, plugin or host-editable module project to AndroidX?
- What if I can’t use Android Studio?
- Add to App
- How do I know if my project is using AndroidX?
- What if I don’t migrate my app or module to AndroidX?
- What if my app is migrated to AndroidX, but not all of the plugins I use?
- I’m having issues migrating to AndroidX
- AndroidX Migration
- Common Questions
- How do I migrate my existing app, plugin or host-editable module project to AndroidX?
- What about if I can’t use Android Studio
- How do I migrate my existing module project to AndroidX?
- How do I know if my project is using AndroidX?
- What if I don’t migrate my app or module to AndroidX?
- What if my app is migrated to AndroidX, but not all of the plugins I use?
- I’m having issues migrating to AndroidX
- AndroidX Migration
- Common Questions
- How do I migrate my existing app, plugin or host-editable module project to AndroidX?
- What if I can’t use Android Studio?
- Add to App
- How do I know if my project is using AndroidX?
- What if I don’t migrate my app or module to AndroidX?
- What if my app is migrated to AndroidX, but not all of the plugins I use?
- I’m having issues migrating to AndroidX
- Unable to migrate Flutter project to AndroidX
- 8 Answers 8
Migrating to AndroidX / Переход на AndroidX
Если вы столкнулись с тем что новые пакеты Flutter требуют поддержки AndroidX, например geolocator ^5.0.0, то для их использования придется совершить этот переход.
Показанием к переходу может быть то, что вы установили новую версию пакета, и во время запуска или работы Flutter приложения случился его сбой, после которого оно закрылось.
Источник https://flutter.dev/docs/development/packages-and-plugins/androidx-compatibility, здесь описано два подхода по переходу к AndroidX:
1. Автоматическими средствами IDE Android Studio (рекомендуемый способ) — рассмотрим его ниже;
2. Ручной (не рекомендуется).
Так же по ссылке есть дополнительная информация и рекомендации.
Источник по переходу к AndroidX в Android Studio и другая информация. https://developer.android.com/jetpack/androidx/migrate
Перевод Flutter приложения на AndroidX в автоматическом режиме с помощью Android Studio
Необходима версия Android Studio 3.2 или более новая.
Нужно открыть Android проект внутри Flutter проекта.
На скриншоте ниже — директория android во Flutter проекте.
Если вы работаете в Android Studio с Flutter проектом, то можете это сделать — нажатием правой кнопки на директорию android и в контекстном меню выбрать: Flutter > Open Android module in Android Studio.
Откроем в новом окне (New Window), чтобы потом вернуться к нашему Flutter проекту.
После того как откроется новое окно, Android Studio произведет все процессы по инициализации проекта, в основном контекстном меню выбираем Refactor > Migrate to AndroidX.
Для восстановления, в случае если вам не подойдет AndroidX, IDE предлагает сделать резервную копию изменяемых файлов. Нажимаем Migrate.
IDE проверяет какие ссылки должны быть изменены, соглашаемся и нажимаем Do Refactor.
Ждем пока IDE завершит все процессы.
Можно проверить что изменился файл android/gradle.properties, в нем должны появится строки:
При переходе к AndroidX может измениться версия gradle, что приведет к долгой сборке вашего приложения. Но такая задержка разовая — в это время происходит загрузка нужной версии gradle из интернета.
Все готово, теперь можно запустить сборку Flutter приложения!
Источник
AndroidX Migration
Note: You might be directed to this page if Flutter detects that your project doesn’t use AndroidX.
AndroidX is a major improvement to 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 frequently than 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 from the Android Studio site.
- 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, save the zip file in your location of preference.
- The refactoring preview shows the list of changes. Finally, click Do Refactor:
- That is it! You successfully migrated your project to AndroidX.
Finally, if you migrated a plugin, publish the new AndroidX version to pub and update your CHANGELOG.md to indicate that this new version is compatible with AndroidX.
What if I can’t use Android Studio?
You can create a new project using the Flutter tool and then move the Dart code and assets to the new project.
To create a new project run:
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 :
Finally, run flutter clean .
If your module contains an android directory instead, then follow the steps in previous section.
How do I know if my project is using AndroidX?
Starting from Flutter v1.12.13, new projects created with flutter create -t
use AndroidX by default.
Projects created prior to this Flutter version must not depend on any old build artifact or old Support Library class.
In an app or module project, the file android/gradle.properties or .android/gradle.properties must contain:
What if I don’t migrate my app or module to AndroidX?
Your app may continue to work. However, combining AndroidX and Support artifacts is generally not recommended because it can result in dependency conflicts or other 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 using the Support Library to AndroidX, so you can use the same plugins even if they haven’t been migrated to AndroidX yet.
I’m having issues migrating to AndroidX
Open an issue on GitHub and add [androidx-migration] to the title of the issue.
Except as otherwise noted, this work is licensed under a Creative Commons Attribution 4.0 International License, and code samples are licensed under the BSD License.
Источник
AndroidX Migration
참고: You might be directed to this page if the tool detects that your project doesn’t use AndroidX.
AndroidX is a major improvement to 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 frequently than 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 from developer.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, save the zip file in your location of preference.
- The refactoring preview shows the list of changes. Finally, click Do Refactor:
- That is it! You successfully migrated your project to AndroidX.
Finally, if you migrated a plugin, publish the new AndroidX version to pub and update your 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 and assets to the new project.
To create a new project run:
How do I migrate my existing module project to AndroidX?
If your project is a module and contains a .android directory, add the following line to pubspec.yml :
Finally, run flutter clean .
If your module contains an android directory instead, then follow the steps in previous section.
How do I know if my project is using AndroidX?
Apps and Modules Your project uses AndroidX if the file android/gradle.properties or .android/gradle.properties contains:
Plugins If a file under the android directory references any old support library package or 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 artifacts is generally not recommended because it can result in dependency conflicts or other 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 using the Support Library to AndroidX, so you can use the same plugins even if they haven’t been migrated to AndroidX yet.
I’m having issues migrating to AndroidX
Open an issue on GitHub and add [androidx-migration] to the title of the issue.
별도 명시된 경우를 제외하고, 이 저작물은 Creative Commons Attribution 4.0 International License를 따릅니다. 코드 샘플에는 BSD License가 적용됩니다.
Источник
AndroidX Migration
Note: You might be directed to this page if Flutter detects that your project doesn’t use AndroidX.
AndroidX is a major improvement to 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 frequently than 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 from the Android Studio site.
- 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, save the zip file in your location of preference.
- The refactoring preview shows the list of changes. Finally, click Do Refactor:
- That is it! You successfully migrated your project to AndroidX.
Finally, if you migrated a plugin, publish the new AndroidX version to pub and update your CHANGELOG.md to indicate that this new version is compatible with AndroidX.
What if I can’t use Android Studio?
You can create a new project using the Flutter tool and then move the Dart code and assets to the new project.
To create a new project run:
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 :
Finally, run flutter clean .
If your module contains an android directory instead, then follow the steps in previous section.
How do I know if my project is using AndroidX?
Starting from Flutter v1.12.13, new projects created with flutter create -t
use AndroidX by default.
Projects created prior to this Flutter version must not depend on any old build artifact or old Support Library class.
In an app or module project, the file android/gradle.properties or .android/gradle.properties must contain:
What if I don’t migrate my app or module to AndroidX?
Your app may continue to work. However, combining AndroidX and Support artifacts is generally not recommended because it can result in dependency conflicts or other 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 using the Support Library to AndroidX, so you can use the same plugins even if they haven’t been migrated to AndroidX yet.
I’m having issues migrating to AndroidX
Open an issue on GitHub and add [androidx-migration] to the title of the issue.
Except as otherwise noted, this work is licensed under a Creative Commons Attribution 4.0 International License, and code samples are licensed under the BSD License.
Источник
Unable to migrate Flutter project to AndroidX
I have a Flutter project in Android Studio. I am planning to migrate to AndroidX. Whenever I do Refactor -> Migrate to AndroidX, Android Studio shows error message:
You need to have compileSdk set to at least 28 in your module build.gradle to migrate to AndroidX.
However I have already set the compileSdkVersion 28 in my app/gradle.build file.
Is there anything else I need to do?
8 Answers 8
I was able to resolve my issue:
- Open the Flutter project into Android Studio
- Right click on the android directory, click on Flutter -> Open Android module in Android Studio. It asked me to upgrade my gradle plugin.
- Then I installed Google Play Services. Tools -> SDK Manager -> SDK Tools and check the Google Play Services.
After the Google Play Services Installed, I did Refactor -> Migrate to AndroidX. It started working.
Note: Do the refactor from the project window you opened in the step 2.
Here is how I got rid of «compileSdkVersion 28» error. But before I solved it this way, I upgraded Android Studio IDE from 3.4.1 -> 3.5.1. I am not sure if this was really needed. So whatever version of IDE you have, see if you can use following steps to solve it.
Go to «Project Structure» — (2nd icon on left of AVD Manager icon on top right corner of IDE)
On «Project Structure» dialog under left navigation click on Project Settings->Modules
After selecting Modules, on the right pane you should see 3 tabs Sources, Paths, Dependencies
Click on Dependencies, if you are getting compileSdkVersion 28 error the SDK version under Dependencies is pointing to version lower than 28 -> Select 28 or higher
Modules -> Dependencies»> 5. Click OK
- Now Refactor->Migrate to AndroidX worked for me
In gradle.build (app) add this
And there are some implementations required to use androidx :-
Источник