Managing Packages In Flutter

Managing Packages In Flutter

Managing Packages In Flutter

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.

I Just Wanted To Develop In Flutter

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:

  • Support multiple API versions by providing backwards compatibility
  • Include libraries that do not come in the standard framework API so you can develop more features
  • Debug and proof your application (I.E. Multidex support)

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

Migrating - A New Project

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.

  1. Open the Android part of your Flutter application by switching to the Project view hierarchy and selecting* Flutter -> Open Android module in Android Studio*

  1. Once opened, Android Studio will ask you to upgrade your gradle version:

Press Update

  1. After it finishes doing so, you will see this warning:
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.

Migrating — An Older Project

  1. Open your gradle.properties file and add the following two lines:
android.useAndroidX = true
android.enableJetifier = true
  1. Open your gradle-wrapper.properties file and change the distributionUrl to this:
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
  1. Upgrade the gradle version to 3.3.0 in your application level gradle file (disregard if you updated gradle as part of migrating a new project):
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
}
  1. Replace all the libraries that relied on the older support libraries with their AndroidX counterparts. For example:
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
//changes to
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

A Hard Truth

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

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Google's Flutter 1.20 stable announced with new features - Navoki

Google has announced new flutter 1.20 stable with many improvements, and features, enabling flutter for Desktop and Web

Top 25 Flutter Mobile App Templates in 2020

Flutter has been booming worldwide from the past few years. While there are many popular mobile app development technologies out there, Flutter has managed to leave its mark in the mobile application development world. In this article, we’ve curated the best Flutter app templates available on the market as of July 2020.

How To Succeed In Mobile App Wireframe Design?

This article covers everything about mobile app wireframe design: what to do and what not, tools used in designing a mobile or web app wireframe, and more.

How much does it cost to make a Flutter app for your business?

Get a Free Quote on Android App Development, iPhone App Development, Ionic App Development, Video Development, ASO, SEO, Google Ads/Adwords, SEO for your app Idea.

Flutter – A Boon to Mobile App Developers

Flutter app development is in trend; ever since flutter - the mobile app development framework, has been helping app developers to build amazing applications.