How to migrate existing flutter project to Android X ? Are there any pro and cons?
You would require to migrate to Android X if you intend to use features that have breaking changes for the latest library. I personally faced this problem cloud_firestore 0.9.0 as the change log says, it required a migration to Android X.
Your Android app is in the android directory of the project. First open the android directory with Android Studio 3.2+. Then Refactor > Migrate to AndroidX. After that also add these to the gradle.properties file in the android directory
android.useAndroidX=true
android.enableJetifier=true
In your IDE menu, go to Refactor and use Migrate to AndroidX...
I did the same mentioned what has been mentioned by the last two answers. (Refactor -> Migrate to AndroidX ...) but it didn't help really. I still got the error by flutter that it's not a AndroidX project.
I fixed it by adding;
android.enableJetifier=true
android.useAndroidX=true
to
android/gradle.properties
Note, there are one in root and the other in android-directory.
Related
Am starting out my first Android project. I have encountered so many errors but i have been able to fix some but this one has become pain in the head. How can I go about it
enter image description here
You can enable Jetifier on your project, which will basically exchange the Android Support Library dependencies in your project dependencies with AndroidX-ones. (e.g. Your Lottie dependencies will be changed from Support to AnroidX)
Android Studio Documentation (https://developer.android.com/studio/preview/features/)
Precondition for Jetifier:
you have to use at least Android Studio 3.2
To enable jetifier, add those two lines to your gradle.properties file:
android.useAndroidX=true
android.enableJetifier=true
Finally, please check the release notes of AndroidX, because jetifier has still some problems with some libraries (e.g. Dagger Android): https://developer.android.com/topic/libraries/support-library/androidx-rn
After upgrating flutter version to Flutter 1.22.0-2.0.pre.78 • channel master I am getting this warning:-
WARNING:
[Processor] Library
'C:\Users....gradle\caches\modules-2\files-2.1\io.flutter\flutter_embedding_debug\1.0.0-b1d9f863db32cb1d6714cf75db4a992ee3765113\b8748b5192a2a0961f5c14f8845331ad5f2225a1\flutter_embedding_debug-1.0.0-b1d9f863db32cb1d6714cf75db4a992ee3765113.jar'
contains references to both AndroidX and old support library. This
seems like the library is partially migrated. Jetifier will try to
rewrite the library anyway. Example of androidX reference:
'androidx/annotation/VisibleForTesting' Example of support library
reference: 'android/support/annotation/NonNull'`
Is this issue will cause some serious issue in future or not. Thanks in Advance :)
This warning exist because on the latest Flutter versions newly created projects will be created with AndroidX automatically.
Starting from Flutter v1.12.13, new projects created with flutter create -t <project-type> 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:
android.useAndroidX=true
android.enableJetifier=true
The warning also stated:
This seems like the library is partially migrated. Jetifier will try to rewrite the library anyway.
This is usually caused by some plugins that was not migrated and Flutter tool uses Jetifier which will automatically migrate those Flutter plugins using the Support Library to AndroidX.
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.
You can open an issue to GitHub if you've encounter other issues when migrating to AndroidX.
A checkbox called use AndroidX artifacts is seen in android studio, when creating a new project(screenshot below)
But in my case its missing. Android studio version 3.6.1(screenshot below)
What could be the reason for this ?
In 3.6.1, Androidx is enabled by default along with enableJetifier.
You can verify it in the gradle.properties files with values as
android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true
When I open my file there is an error. I already clean, rebuild and invalidate caches It is possible to upgrade or downgrade my android studio? thanks in advance
With Android Studio 3.2 and higher, you can quickly migrate an existing project to use AndroidX by selecting Refactor > Migrate to AndroidX from the menu bar.
If you have any Maven dependencies that have not been migrated to the AndroidX namespace, the Android Studio build system also migrates those dependencies for you when you set the following two flags to true in your gradle.properties file:
android.useAndroidX=true
android.enableJetifier=true
To migrate an existing project that does not use any third-party libraries with dependencies that need converting, you can set the android.useAndroidX flag to true and the android.enableJetifier flag to false.
Just open your internet connection and it will automatically update your resources in android studio and it works.
I've refactored my Android Studio codebase to AndroidX successfully. But it is causing a few problems with some of my libraries.
I need to revert it since the app is going into production soon. How can I do it?
I had gone through the same, Follow the steps to undo the AndroidX Migration:
Remove following lines in gradle.properties:
android.enableJetifier=true
android.useAndroidX=true
Remove AndroidX dependencies in build.gradle of your app and replace them with their equivalent Non AndroidX dependencies:
e.g.
implementation 'androidx.core:core:1.0.0-beta01'
implementation 'androidx.appcompat:appcompat:1.0.0-beta01'
Sync Project with Gradle Files
After syncing you may have import errors in java files, you can remove the androidx imports and re add the equivalent non androidx imports
I hope it will help everyone facing migration rollback problem. If you get any conflict issues while performing above steps in Android Studio, try to clean and rebuild the project.
You can simply choose Migrate App to appCompat from Refactor menu in Android Studio.
Also, don't forget to delete these lines from gradle.properties:
android.useAndroidX=true
android.enableJetifier=true
I couldn't simply roll back in version control, because the app I wanted to roll back was androidx from its initial commit, but I was tasked with integrating the app module into a larger project without androidx.
Here's what I did:
Try syncing gradle and inevitably you'll get some kind of error. Here is the first error I saw:
Error: Attribute application#appComponentFactory
value=(androidx.core.app.CoreComponentFactory) from
[androidx.core:core:1.1.0] AndroidManifest.xml:24:18-86 is also
present at [com.android.support:support-compat:28.0.0]
AndroidManifest.xml:22:18-91
value=(android.support.v4.app.CoreComponentFactory)
Take note of the androidx package in the above error.
Run gradlew dependencies inside the module you're trying to migrate back.
Search the output for the androidx package mentioned in the above error. Figure out which of your dependencies from your build.gradle file is bringing in that package, then revert that package to its equivalent support library mapping.
Repeat steps 1-4 until Gradle sync finishes successfully.
Now you need to search all your .java files for androidx and replace each import statement with its support library package name. Tip for this step: turn on "Add unambiguous imports on the fly" in Android Studio preferences and just delete all the androidx imports. Most of them will auto-repopulate with the correct support packages.
Now your project should build successfully, but you'll likely run into runtime crashes due to androidx view components used in layout files.
Search all xml files for androidx and com.google.android.material, and replace each view with its support equivalent name.
Don't forget to fix any compilation issues in your tests, and re-run them to make sure they still all pass.
Do a hard reset on repository which was working before migration to android x.
Delete the node_modules folder, and type npm install.