Migrate to AndroidX - android

I'm trying to migrate to AndroidX and we use this library in our project. However, this is currently causing an issue in our project:
Unable to resolve dependency for ':module#buildType/compileClasspath':
Failed to transform file 'localytics-1.3.0.aar' to match attributes
{artifactType=processed-aar} using transform JetifyTransform
Removing the library makes this issue disappear.
Is there any workaround that would allow me to migrate to AndroidX til this library is migrated?
Per the documentation: https://developer.android.com/jetpack/androidx/migrate
I have updated my gradle.properties. The issue is not with setup, the issue is that localytics does not seem to support androidX. I want to confirm this if anyone knows since contacting them results in no answer (they have poor costumer service).

Someone posted a patch on Github:
Clone the repository.
Update the analytics-android-integration-localytics project to the latest
Android updates, including AndroidX. Generate a jar file instead of
an aar file. (This is the winning item here. It must be a jar file
for it to work. An aar file isn't needed anyway since there aren't
any resources in this project's aar file.)
Remove the existing maven dependencies in the consuming project.
Import the jar file as new module in the consuming project.
Rebuild the consuming project.

First of all please add following line in gradle.properties
android.useAndroidX=true
android.enableJetifier=true
Can you please share your build.gradle ? May be there can have another issue. Please update the following localytics library like this.
classpath 'io.fabric.tools:gradle:1.25.1' to
classpath 'io.fabric.tools:gradle:1.27.0'

If jetfier is not working on that library, I think you can try some workarounds such as:
Update the library (is v1.3.0 the latest version of that AAR?)
Disable jetfier as a whole (setting android.enableJetifier=false on gradle.properties)
Disable jetfier on that library only via:
on gradle.properties
android.enableJetifier=true
android.jetifier.blacklist = .*localytics.*
android.useAndroidX=true
This last option requires Android Gradle Plugin version

Related

How do I fix android builder error EvalissuesException in android studio

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

AndroidX Jetifier unable/failed to transform 3rd-party transitive dependency that still use Support Library

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

import android.annotation Cannot resolve symbol

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.

Undo migration to AndroidX

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.

AndroidX migrate dependency / libraries

I have successfully migrated my project to AndroidX. App is running perfectly, but I am getting compile time errors, because my dependencies use support package.
Reason of this error
Because PhotoView is a dependency class, which uses android.support.v7.widget.AppCompatImageView which is no more available in my project. Because it is now androidx.appcompat.widget.AppCompatImageView
Project still run?
Yes, android.enableJetifier convert this dependency to AndroidX at runtime, but I want to get rid of compile time errors.
Is there a quick fix for now?
If you depend on a library that references the older Support Library, Android Studio will update that library to reference androidx instead via dependency translation. Dependency translation is automatically applied by the Android Gradle Plugin 3.2.0-alpha14, which rewrites bytecode and resources of JAR and AAR dependencies (and transitive dependencies) to reference the new androidx-packaged classes and artifacts. We will also provide a standalone translation tool as a JAR.
I see (using ./gradlew app:dependencies) that rxbinding's design dependency is updated to the new com.google.android.material dependency. Passing com.google.android.material.snackbar.Snackbar to a library function that references android.support.design.widget.Snackbar themselves makes Android Studio show a compiler error, but actually compiling and running the app works. I assume AS can't really handle these changes yet.
It seems there are some caching issues, removing .idea/libraries and performing a Gradle sync makes the errors disappear.
I solved this issue by deleting .idea folder and syncing project again.
This seems a bug of IDE not Jetifier, it does not re-sync dependencies after migrating.
Jetifier does its work well. It converts all dependencies support libraries into androidx at building time. See #this post for good explaination.
My fix for this was converting the library with the compile time error to AndroidX and submitting a pull request to the library.

Categories

Resources