I'm migrating my dependencies for an Android P test to the androidx dependencies. For some not very clear reasons my project does not compile anymore (and no I won't provide the details to avoid a distinct problem). I found out (via gradlew dependencies) that the databinding uses the "oldschool" dependency android.arch.lifecycle:runtime:1.0.3 instead of androidx.lifecycle:lifecycle-runtime:2.0.0-beta01. I guess that could be one reason.
Any idea how to force using the new package names/dependencies?
I face the similar problem, the Data Binding library use the support library, some classes may conflict with the AndroidX. I have to remove the DataBinding for now.
I just read this release note, it said that this issue had been fixed, but I didn't see the effect.
Enabling AndroidX in the gradle.properties fixed this problem for me:
android.useAndroidX=true
android.enableJetifier=true
See https://developer.android.com/jetpack/androidx#using_androidx:
android.useAndroidX: When set to true, the Android plugin uses the
appropriate AndroidX library instead of a Support Library. The flag is
false by default if it is not specified.
android.enableJetifier: When
set to true, the Android plugin automatically migrates existing
third-party libraries to use AndroidX by rewriting their binaries. The
flag is false by default if it is not specified.
Check Layout files maybe there are Views left which use support library instead of androidx
for example
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
change it to
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
I tried that while I had a weak internet connection, so I skipped to update to Android Studio 3.2. That was my fault. With that upgrade (the unziping took almost an hour no idea why) I was requested also to upgrade my build tools to com.android.tools.build:gradle:3.2.0-beta04 (or whatever is the newest version matching for your Android Studio version (I would not install the 3.3.0-alpha03) and upgraded the gradle wrapper to 4.6.
Now the dependencies are gone and I'm happy.
1- Add this line into build.gradle
android {
dataBinding {
enabled = true
}
}
2- gradle.properties(Project Properties)
android.databinding.enableV2=true
In my case, the error was because the tool to migrate to AndroidX does not work perfectly. There was still some layout files using some old support libraries. After fixing those files, everything went well =)
To fix, every support library that was being used in those layout files, I changed to the right one following this link: https://developer.android.com/jetpack/androidx/migrate
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'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
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
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.
I don't really understand why my appcompat version is not accepted
Please help
click to see image
This is a warning, your app will still run.
One or more of your transitive dependencies is requesting different version of of the Android Support Library that you are not requesting directly yourself, resulting in this conflict. You will need to run a Gradle dependency report and find out what is causing the problem, then manually request those artifacts yourself with your desired version (presently, 27.0.1).
I think in your case facebook is using old version, you should try updating facebook dependency version to latest.
You can see this answer as well.
You have probabelly some libraries that use older versions of some others support libraries (not especially AppCompat), so you have to override them manually in the gradle to get rid of this warning.
You have to repeat this until the warning disapear :
When you see the hint, copy and past the library and update the version number : for example if in the hint you have
"blablabla... example include blablabla...
com.android.support:support-core-ui:26.0.1"
Add this to the dependencies section of the build.gradle script :
implementation 'com.android.support:support-core-ui:27.1.1'