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.
Related
I've recently migrated my project to use AndroidX
My apps crashes, after I migrate to AndroidX, due to library still using Support Library. Here's a list of my 3rd-party dependencies/library, that failed to transform into AndroidX:
com.clevertap.android:clevertap-android-sdk:3.4.2
com.readystatesoftware.chuck:library:1.1.0
com.ncapdevi:frag-nav:2.4.0
jp.wasabeef:recyclerview-animators:2.3.0
com.github.chivorns:smartmaterialspinner:1.1.6
com.facebook.android:facebook-android-sdk:5.0.1
com.github.PierfrancescoSoffritti:AndroidYouTubePlayer:7.0.1 (I still cannot upgrade it to 10.x.x, because major API changes)
com.github.nikartm:image-support:1.0.5
My Setups:
AS & AGP: 3.6.2
targetSdk: 29
minSdk: 16
Data & View Binding: Both enabled
Gradle DSL: Kotlin
Gradle: gradle-6.0.1-all
What I've done so far:
Using Refactor -> Migrate to AndroidX tools from Android Studio, but ended-up force close it, because takes a long time
android.enableJetifier=true & android.useAndroidX=true
Using the shell scripts to manually mapping artifact, class and imports from Support Library to AndroidX, thanks #Danlew, also #Danlew mentioned in ADS '19 talks here
Already checked my :app:dependencies that 3rd-party dependencies already migrated to use AndroidX artifacts, but only a few of them (failed for the above dependencies list)
Deleting ./root_project/.idea, ./root_project/.gradle & ~/.gradle/caches (to fix compile-error/IDE error, references: AndroidX migrate dependency / libraries
Understanding the jetifier: What is Jetifier? & official android docs
Did a workaround to use AndroidX for annotation processor like: Glide & Dagger
Checking the ~/.gradle directories for the jetified-* libs the jetified aar exist, unfortunately it's failed for clevertap & others libs listed above.
My conclusions, the jetifier works by rewriting the binary .class of our 3rd-party library if Support Library imports/class detected, and modify (jetified/mapping it) into AndroidX respectively.
But in my case, the dependencies listed above doesn't use correct AndroidX imports and resulting runtime crash, due to having a transitive dependent for Support Library.
Does jetifier currently doesn't support transitive dependency inside 3rd-party library as well? But, strangely it works for a few library (unlisted from above)
[UPDATED 1]
In the meantime (quickfix):
I did downloading all the transitive dependencies of the libraries exhaustively one-by-one
Using jetifier-standalone commands instead for the libraries aar
Manually adding the libraries aar and its dependencies to app/build.gradle.kts as flatDirs
Is this really a workaround, is there anything better I can do?
[UPDATED 2]
I've using a maintained version of chuck as well. But found this same issue as well:
cannot generate view binders com.sun.tools.javac.code.Symbol$CompletionFailure: class file for android.support.v7.widget.AppCompatImageView not found
After checking my 3rd-party libs, I also ended-up manually adding the aar after I use jetifier-standalone for this library:
com.clevertap.android:clevertap-android-sdk:3.4.2
com.github.nikartm:image-support:1.0.5
Many also recommends to use api instead of implementation but for me, I don't want to bloated my project with transitive dependency
In other SO also recommends below:
either remove the library,
forked it to support androidx / waiting for the author to upgrade it
manually using jetifier-standalone for those specicif libs, and include as local aar (this is my best approach, right now)
Unless the jetifier able to state this into official documentation, for its limitation: https://developer.android.com/jetpack/androidx/releases/jetifier
Seems like there's the least we can do, and hope, many of the 3rd-party authors will upgrade to AndroidX soon.
Here's a bonus article for references:
You can use can-i-drop-jetifier libs to detects does your libs (transitively) needs jetifier enabled or not
The time is right to migrate to AndroidX with this baby-steps
Better structure packaging with AndroidX and also a headache along the way
Turns out my current workaround was using this approach: https://github.com/bumptech/glide/issues/3080#issuecomment-495430590
Magical regex to turns a blacklist into a whiteliset
android.jetifier.blacklist=^(?!.*[\\\\/](com\\.github\\.bumptech\\.glide|com\\.clevertap\\.android|com\\.facebook\\.android|com\\.github\\.nikartm|com\\.github\\.PierfrancescoSoffritti|com\\.github\\.prolificinteractive)[\\\\/]).*$
If NoClassDef exceptions thrown, then I add the library package name into the android.jetifier.blacklist to whitelisted them.
In the above cases, I'm trying to whitelist:
glide
clevertap
nikartm
facebook-sdk
YoutubeAndroidPlayer (v7) still not using v10
prolificinteractive
When the implementation 'com.karumi:dexter:6.0.0' is added in build.gradle file, Error is shown on line number 24 while implementing appcompat:implementation 'com.android.support:appcompat-v7:26.1.0'
its the build.gradle(Module:app)
Error in Gradle
From your gradle error message, it is seen that your are using the andorid earlier project structure library.
You are trying to implement implementation 'com.karumi:dexter:6.0.0' library which is using the androidx support library structure.
Hence, your are getting that error as you cannot use both the structure as they have been made and organized complete differently.
Solution:
Shift to androidx library structure if you really want to use that library.
Refer this official documentation of Google Android to migrate to andoirdx from android -
Google Developers Documentation
The library you are trying to use is using AndroidX libraries and you are using Andeoid support libraries in your project. Either migrate your project to androidx or ise an older version of the library which use android support libraries.
You should migrate your project AppCopact to AndroidX. For migrating project AppCompact to Androidx Go Refactor -> Migrate to Androidx then tick on BackUp Project and Migrate. After Migration The com.karumi:dexter:6.0.0 library will work perfectly.
My current project is quite stable. Presently I don't want to migrate to Androidx. But I need to use this com.pierfrancescosoffritti.androidyoutubeplayer:core:10.0.3 library in my project, which is migrated to Androidx. So when I'm importing this library it causes gradle build failure.
I found many ways for migrating to Androidx but not the other way.
One solution I can think of downloading the library and replace the Androidx libraries with support and then import. Apart form this is there any other way ? Like the reverse of jetifier.
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.
I find two new refactor commands, what are the exact functions of
refactor>migrate app to appCompat
refactor>migrate to androidX
Support (compatibility) libraries was changed to AndroidX libraries by Google.
So in the nearest future support libraries won't be supported anymore.
So "migrate to androidX" will do the following:
Android studio will change all imports in your class from android.support. * to androidx. *
Dependencies of your build.gradle will be also changed to relevant androidX libs