implementing card view in build.gradle - android

I am trying to implement card view by implementing it in my build.gradle.
However while doing this, I am getting an error. It is saying
"Version 28 (intended for Android Pie and below) is the last version of the legacy support library, so we recommend that you migrate to AndroidX libraries when using Android Q and moving forward. The IDE can help with this: Refactor > Migrate to AndroidX... less... (Ctrl+F1)"
I understand how to do it but am not sure if I should since I am not getting any build errors and my gradle is still syncing. Can someone tell me whats going on?

You are using androidx libraries together with a very old version of support library of cardview.
Remove the dependency of support library
//implementation 'com.android.support:cardview-v7:16.0.4'
and add:
implementation 'androidx.cardview:cardview:1.0.0'
More info about androidx here.
You have another option.
Just add the MaterialCard included in the official Material Components library:
implementation 'com.google.android.material:material:1.1.0-alpha10'
and in your xml you can use:
<com.google.android.material.card.MaterialCardView
...>

Just open your project and make the compile and target version to 28 , then sync then go to refractor on toolbar of studio , there you will see migrate to android x just tap on that. It will resolved all your issue.

Related

adding com.android.support:design:28.0.0 dependency

I am trying to add Floating Edit text to my app. For this have added 'com.android.support:design:28.0.0' dependency to my build.gradle (;app).
I'm getting this following error if try to run the project.
if need to refactor>Migrate to androidX :(please guide me to the process)
You don't need this dependency since you are using the Material components library (it is a drop-in replacement for Android's Design Support Library).
Just remove it.

What is the AndroidX equivalent of support-compat library?

I'm trying to implement notifications following the example at https://developer.android.com/training/notify-user/build-notification
However, the guide shows an implementation of
dependencies {
implementation "com.android.support:support-compat:28.0.0"}
But when I try to add the dependency in my gradle file I get this error:
Version 28 (intended for Android Pie and below) is the last version of the legacy support library, so we recommend that you migrate to AndroidX libraries when using Android Q and moving forward. The IDE can help with this: Refactor > Migrate to AndroidX..
So what is the AndroidX version of this library?
That would be
implementation "androidx.core:core:1.3.2"
You can find a list of all the mapping to AndroidX at https://developer.android.com/jetpack/androidx/migrate/artifact-mappings

Dependencies cannot be compiled in android studio

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.

Is it possible to add a library created in android-x as module in my project which is not yet migrated to android-x?

I am trying to add a new module to my project to use as a library. But the issue is the new module developed using android x components. Is it possible to use the new module with my current project without migrating to android x?.
Technically not possible.
The simple reason is that Gradle cannot build an android app having both android support libraries and androidx libraries without any conversion, this would cause a merge conflict on classes.
What happens behind the scene during a build
Library A
implementation 'com.android.support:appcompat-v7:28.0.0'
Library B
implementation 'com.android.support:appcompat-v7:26.0.0'
Because the classes inside both packages are the similar: Gradle merges them to form one.
Now imagine the scenario
What happens behind the scene during a build
Library A
implementation 'com.android.support:appcompat-v7:28.0.0'
Library B
implementation 'androidx.appcompat:appcompat:1.0.0'
Now gradle becomes confuse because they're both appcompat libraries but their classes differs, hence they cannot be merged so it throws an error.
Nevertheless users whose project are on androidx can still use android support referenced libraries with the help of Jetpack Jetifier tool which would convert the support references into corresponding androidx libraries during build.
Unless you want to develop you own tool naming it UnJetifier then the option for building both android support referenced libraries and androidx libs in a support project would be possible. Best advice would be to migrate your app to androidx cause you are missing out on lots of features.

dependency "androidx.core:core-ui" not found

When adding constraint layout group to my project, Android studio auto add the dependency in gradle:
implementation 'androidx.core:core-ui:+'
But I've got this error message:
Failed to resolve: androidx.core:core-ui:+
I couldn't find any way to add corresponding androidx dependency, the only solution I know so far is using support lib but It against the guideline to move everything to androidx.
com.android.support:support-core-ui:28.0.0
Is there any androix dependency which includes the ConstraintLayout Group?
Use this in your app gradle file instead...
implementation 'androidx.legacy:legacy-support-core-ui:1.0.0-alpha1'
Try adding this to your build.gradle file implementation 'androidx.constraintlayout:constraintlayout:1.1.0'
constraint layout does not show up for me to drag it into the layout editor(3.2 canary) but I can use it by writing the code in xml and adding this library. For any other dependencies, try writing the specific dependency in gradle, it appears core-ui for androidx not working yet.
Edit:
There should be a download icon next to the dependencies you don't have. You can click on it and there will be a pop up stating the dependency name. In Studio 3.2 Canary on windows, it is not adding these dependencies automatically, which is why my solution is to implement the dependency in build.gradle manually.

Categories

Resources