What is the AndroidX equivalent of support-compat library? - android

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

Related

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.

implementing card view in build.gradle

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.

How to get the latest Room version?

Would you know where to get the latest version for Room ?
On this Android Studio page, it is quoted that the latest Room version is 2.1.0-alpha3 but when I put this version in my build.gradle file, the project cannot compile and the following error is shown :
ERROR: Failed to resolve: android.arch.persistence.room:runtime:2.1.0-alpha3
Show in Project Structure dialog
Affected Modules: app
it is quoted that the latest Room version is 2.1.0-alpha3
It is.
when I put this version in my build.gradle file, the project cannot compile and the following error is shown
Your version is fine. Your artifact is the problem.
All new libraries are AndroidX. Your choices are:
Stick with whatever version you are using right now and keep your android.arch.persistence.room:runtime artifact and its classes, or
Migrate to AndroidX, in which case you would use androidx.room:room-runtime as the artifact, and need to change your code to reference the androidx classes for Room and everything else
The thing is, if you'r using AndroidX then the latest is 2.1.0-alpha3, or, if you are using Support libraries then it's 1.1.1 or whatever is latest and that's what mentioned in the documentation. As mentioned by CommonsWare, it's the artifact, and to find out the mappings, see this mapping documentation. And AndroidX is:
The AndroidX library contains the existing support library and also
includes the latest Jetpack components.
Example using support libraries:
dependencies {
// Other libraries...
implementation 'android.arch.persistence.room:runtime:1.1.1'
annotationProcessor 'android.arch.persistence.room:compiler:1.1.1'
}
The solution is to check AndroidX when starting a new project in Android Studio, then in the App Module Build.Gradle file the following works perfectly :
def room_version = "2.1.0-alpha03"
implementation "androidx.room:room-runtime:$room_version"
kapt "androidx.room:room-compiler:$room_version" // use kapt for Kotlin

Android studio 3.2 canary Migrate feature

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

Cannot resolve symbol 'MediaSessionCompat'

I cannot import MediaSessionCompat.
The import statement for importing the whole android.support.v4.media library does not show up in the Android Studio "IntelliSense" and it cannot resolve the symbol for anything inside it.
Do I have to make some kind of extra configuration to get this import, like in app build.gradle?
Add these to your dependencies and sync Gradle:
Pre-AndroidX
implementation 'com.android.support:support-compat:28.0.0'
implementation 'com.android.support:support-media-compat:28.0.0'
Post-AndroidX
implementation 'androidx.core:core:1.8.0'
implementation 'androidx.media:media:1.6.0'
Note from official documentation:
With the release of Android 9.0 (API level 28) there is a new version of the support library called AndroidX which is part of Jetpack. The AndroidX library contains the existing support library and also includes the latest Jetpack components.
You can continue to use the support library. Historical artifacts (those versioned 27 and earlier, and packaged as android.support.*) will remain available on Google Maven. However, all new library development will occur in the AndroidX library.
We recommend using the AndroidX libraries in all new projects. You should also consider migrating existing projects to AndroidX as well.
The latest dependencies are:
implementation 'androidx.core:core:1.1.0'
implementation 'androidx.media:media:1.1.0'
def core_version = "1.9.0"
// Java language implementation
implementation "androidx.core:core:$core_version"
// Kotlin
implementation "androidx.core:core-ktx:$core_version"
implementation "androidx.media:media:1.6.0"

Categories

Resources