How to get the latest Room version? - android

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

Related

AndroidX dependencies error on adding firebase to android

I am working on an android project, When I tries to add firebase dependency to project following Build error occurs. I have tried migrating to appCompat but didnt workded.
This project uses AndroidX dependencies, but the 'android.useAndroidX' property is not enabled. Set this property to true in the gradle.properties file and retry.The following AndroidX dependencies are detected: androidx.versionedparcelable:versionedparcelable:1.0.0, androidx.fragment:fragment:1.0.0, androidx.slidingpanelayout:slidingpanelayout:1.0.0, androidx.core:core:1.0.0, androidx.customview:customview:1.0.0, androidx.swiperefreshlayout:swiperefreshlayout:1.0.0, androidx.interpolator:interpolator:1.0.0, androidx.loader:loader:1.0.0, androidx.drawerlayout:drawerlayout:1.0.0, androidx.viewpager:viewpager:1.0.0, androidx.collection:collection:1.0.0, androidx.localbroadcastmanager:localbroadcastmanager:1.0.0, androidx.lifecycle:lifecycle-common:2.0.0, androidx.arch.core:core-common:2.0.0, androidx.annotation:annotation:1.1.0, androidx.legacy:legacy-support-core-ui:1.0.0, androidx.lifecycle:lifecycle-livedata:2.0.0, androidx.lifecycle:lifecycle-viewmodel:2.0.0, androidx.lifecycle:lifecycle-livedata-core:2.0.0, androidx.arch.core:core-runtime:2.0.0, androidx.legacy:legacy-support-core-utils:1.0.0, androidx.documentfile:documentfile:1.0.0, androidx.cursoradapter:cursoradapter:1.0.0, androidx.lifecycle:lifecycle-runtime:2.0.0, androidx.coordinatorlayout:coordinatorlayout:1.0.0, androidx.asynclayoutinflater:asynclayoutinflater:1.0.0, androidx.print:print:1.0.0
dependencies added without firebase are as follows:
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:2.0.4'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0'
Please help to resolve above issue.
android.useAndroidX=true
The Android plugin uses the appropriate AndroidX library instead of a Support Library.
android.enableJetifier=true
The Android plugin automatically migrates existing third-party libraries to use AndroidX by rewriting their binaries
Add both line in your gradle.properties file.
Then clean project and rebuild project.
May be your problem will be solved.
If not let me know.
You are currently using Android based library should be migrated to Androidx.
I suggest you migrate your project in Androidx.
You easily got more post How to migrate android to androidx my project.

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

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"

WorkManager: Dependency Issue with Kotlin

I'm getting the following error while trying to use Work Manager. I've migrated my project to AndroidX and all other architecture components are working.
def work_version = "1.0.0-alpha02"
/* Work Manager for Background Tasks */
implementation "android.arch.work:work-runtime:$work_version"
implementation "android.arch.work:work-firebase:$work_version"
I'm quite sure I need some dependencies from the Support Library. But I have no clue which one's they are.
I've tried adding the annotations package since the error says it can't find a class file for RestrictTo$Scope. Still doesn't work.
implementation "com.android.support:support-annotations:28.0.0-alpha1"
You are including a reference to the wrong support library, you want the androidx one.
androidx.annotation
Look in
AndroidX refactoring
you will find
androidx.annotation:annotation:1.0.0-alpha1
to correspond with
com.android.support:support-annotations
Make sure that you have only libraries for one or the other kind in your dependencies (project wide).

Android ViewModel with appCompat v27.0.0

I am trying to use the Android architecture components ViewModel in a project with the latest com.android.support:appcompat-v7:27.0.0. The appcompat already contains everything from android.arch.lifecycle:runtime:1.0.3 and android.arch.lifecycle:compiler:1.0.0. However it does not seem to contain for example android.arch.lifecycle:extensions:1.0.0which includes the ViewModel class. There still does not seem to be a version 1.0.3 of the extensions but if I try using 1.0.0 I get the following error:
Error:Execution failed for task ':app:preReleaseBuild'.
Android dependency 'android.arch.lifecycle:runtime' has different version for the compile (1.0.0) and runtime (1.0.3) classpath. You should manually set the same version via DependencyResolution
I can fix this like that:
implementation ("android.arch.lifecycle:extensions:1.0.0"){
exclude module: "runtime"
}
but this can not be the final solution. What am I missing?
LiveData , ViewModel , Room and Paging Library all of these libraries are part of android architecture components . None of these library are part of support library .
To add architecture components as a dependency on your gradle file you need to add them separately and their associate annotation processor like this
// Architecture Components
compile 'android.arch.persistence.room:runtime:1.0.0'
annotationProcessor 'android.arch.persistence.room:compiler:1.0.0'
compile 'android.arch.lifecycle:extensions:1.0.0'
annotationProcessor 'android.arch.lifecycle:compiler:1.0.0'
for detail documentation please see the official documentation adding architecture components to your project

Categories

Resources