If you are developing in Flutter and have not run into the following problem, pay attention, because it will happen to you (sooner or later). You are browsing the Flutter packages website, looking for one that will cater to your needs. Once you find one, you inspect its README.md page and you see the following:
What?
For those of you that are unaware, AndroidX is the new support library that Google has been pushing for some time now to replace the older support libraries that are found inside Android Studio. What does this have to do with me, you say.
Well, in short, everything.
Getting your head around the whole support libraries issue can seem irrelevant, but it is something you need to understand. This is because, whatever your application is doing, the code you are writing relies on the support libraries. Support libraries are there to help you:
As I stated earlier, since the release of Android 9 (API level 28), the newer version of the support libraries is called AndroidX. You can still use the older support libraries, but as stated on their website, all new development will happen in AndroidX libraries. So, if you are developing a new application, you might as well already use the new support libraries. And if you already have an application, you seriously need to consider migrating it to use AndroidX.
Photo by Rohan Reddy on Unsplash
To migrate a new Flutter project, you can use the built in functionality found inside Android Studio. An option inside the top menu, ***Refactor->Migrate to AndroidX ***is supposed to do the hard work for you. But if it were that easy, would I be writing this article?
When you create a new Flutter project, your compileSdkLevel will already be set to 28, but if you try migrating with the method mentioned above, you will get the following popup:
Wait? Didn’t I just set this up?
This is an annoying bug in Android Studio, which will hopefully be fixed. We are left with doing the migration ourselves.
Press Update
WARNING: API 'variantOutput.getProcessResources()' is obsolete and has been replaced with 'variantOutput.getProcessResourcesProvider()'.
It will be removed at the end of 2019.
For more information, see https://d.android.com/r/tools/task-configuration-avoidance.
To determine what is calling variantOutput.getProcessResources(), use -Pandroid.debug.obsoleteApi=true on the command line to display a stack trace.
Affected Modules: app
Yet again, this is something that needs to be fixed, but we will persevere and move on. The next steps are similar to what is needed to be done to migrate an existing project, so just follow on through to the next section.
android.useAndroidX = true
android.enableJetifier = true
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
}
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
//changes to
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Before you can go along, happily skipping, enjoying your triumphant victory over the platform, you need to face a harsh truth:
It’s impossible to fully migrate your app to AndroidX if it’s actively using any plugins that rely on the old support library. If your app depends on plugins that use the old
android.support
packages, you’ll need to avoid using AndroidX.
Taken directly from Flutter’s documentation, the above sentence completely obliterates your ability to interleave packages that use different versions of the support library. Where will this happen to you? If for instance you want to get a user’s location, you will notice that the permissions package relies on the older support libraries, but the location package uses the newer AndroidX libraries. You can always try to use the version of a package before it moved to AndroidX, but then you might face bugs that have been fixed in later versions or other compatibility issues.
All in all, what you are left with is a sort of game of mix and match, where you have to choose what packages you use wisely.
#flutter #mobile-apps