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.
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
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
i have cloned a gitlab repository to a laptop. the import statements are gray in color(like unused imports). so the classes are full of errors. initially i was using this same project in another laptop. there everything was fine. should i download something or should i change some settings. the previous laptop had android studio version 3.4. this laptop is having studio version 3.3.1. does this version make any difference.
also in settings page, project-level settings is collapsed. it is not expanded. i dont know if there is any path set or default gradle wrapper is used. is this the reason for the problem?
You can set up your project with androidX by following below procedure
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.
also add missing dependency in your build.gradle file
check list of dependencies over here
As Google APIs for Android introduced breaking changes as here I found my self un able to compile my react native android app, there are two things I need to know about:
How to avoid migrating to AndroidX and compile my project as I did before?
For example, when I have this error:
node_modules/react-native-firebase/android/src/main/java/io/invertase/firebase/ReactNativeFirebaseAppRegistrar.java:20: error: package android.support.annotation does not exist
import android.support.annotation.Keep;
how would include that missing package into build.gradle of that module?
I tried:
dependencies {
compile 'com.android.support:support-annotations:27.1.1'
}
but it did not help..
You can disable or avoid androidX with the following step
go to your android/gradle.properties file and paste or update the following
android.useAndroidX=false
android.enableJetifier=false
Although it does not update libraries we import or install, So all the libraries should be in AndroidX support otherwise project will not compile with this change I'm also having the same issue in my case project is fine but the problem is with the library called mapbox which have not support androidx I post the issue here you can check issue and comments.
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.