I am getting error: package android.arch.lifecycle does not exist and i tried to resolve it,
i used below links : but none of these resolve it:
Failed to resolve: android.arch.lifecycle:extensions:1.0.0-alpha1 android studio 3.0
Could not resolve android.arch.lifecycle:extensions:1.1.0
i have below dependencies :
// Room components
implementation "android.arch.persistence.room:runtime:$rootProject.roomVersion"
annotationProcessor "android.arch.persistence.room:compiler:$rootProject.roomVersion"
androidTestImplementation "android.arch.persistence.room:testing:$rootProject.roomVersion"
// Lifecycle components
implementation "android.arch.lifecycle:extensions:$rootProject.archLifecycleVersion"
annotationProcessor "android.arch.lifecycle:compiler:$rootProject.archLifecycleVersion"
Recently I got this link:
https://developer.android.com/jetpack/androidx/releases/lifecycle#java
which says : The APIs in lifecycle-extensions have been deprecated. Instead, add dependencies for the specific Lifecycle artifacts you need.
Does this mean now I need to use individual packages?
The android.arch packages have been deprecated, try using androidx packages instead. Also make sure you've added google() in your build.gradle.
Finally i got the answer.
android.support is deprecated , i migrated to androidx via following links:
https://medium.com/androiddevelopers/migrating-to-androidx-tip-tricks-and-guidance-88d5de238876
https://developer.android.com/jetpack/androidx/migrate
And at last if you get error like buttler knife/ (or any third party lib) not resolved, find android x compatible version
i used:
// butter knife
implementation 'com.jakewharton:butterknife:10.0.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.0.0'
Related
I have facing the following error while building the project. And unable to solve the same after trying it for whole day.
error: To use RxJava2 features, you must add `rxjava2` artifact from Room as a dependency. androidx.room:room-rxjava2:<version>
public abstract java.lang.Object clearAllBillers(#org.jetbrains.annotations.NotNull()
^
below are my dependancies inside the build.gradle
implementation("androidx.room:room-rxjava2:2.3.0")
implementation "androidx.room:room-runtime:2.3.0"
implementation "androidx.room:room-ktx:2.3.0"
implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
kapt "androidx.room:room-compiler:2.3.0"
I have done trying already existing solutions such as upgrading
classpath 'com.android.tools.build:gradle:7.3.1'
Also tried to do invalidate cache and clean project.
Still not able to solve the issue.
Please help me if you have any idea to get it resolve.
Thanks in advance!!!❤️
Not sure why haven't you received an answer quicker (because this question has an easy solution)
you just need to add
implementation("androidx.room:room-rxjava2:2.4.3")
to your build.gradle (for your app or module)
(source)
I'm working with old version of appcompat, but error after migrate to androidX.
implementation 'com.android.support:appcompat-v7:28.0.0'
Should i use implementation instead of runtimeOnly ?
After androidx migration your dependency would have been changed to following:
implementation "androidx.appcompat:appcompat:1.5.1"
If above is already present in your build.gradle then you can safe remove appcompat-v7 dependency.
As far as using implementation or runtimeOnly it totally depends upon dependency usage. If its usage in compile time then use implementation or if this just require in runtime use runtimeOnly.
To get your answer please refer to the link: Dependency configurations
According to the description mentioned in above link:
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
I'm trying to add ViewModel and LiveData to a Kotlin app. I have the following dependencies added to my module's build.gradle:
implementation "android.arch.lifecycle:extensions:1.1.1"
kapt "android.arch.lifecycle:compiler:1.1.1"
testImplementation "android.arch.core:core-testing:1.1.1"
I'm given the following error:
Android dependency 'android.arch.lifecycle:runtime' has different version for the compile (1.0.0) and runtime (1.1.1) classpath. You should manually set the same version via DependencyResolution
Removing the first line (extensions) fixes the issue, indicating that the error is coming from there, but I can't figure out why.
As #RedBassett mentions Support libraries depends on this lightweight import (runtime library) as explained at android developers documentation.
This is, android.arch.lifecycle:runtime:1.0.0 is spreading up in the dependency tree as a result of an internal api (transitive) import so in my case I only had to include extensions library as "api" instead of "implementation" so that it will override its version to the highest (1.1.1).
In conclusion, change
implementation "android.arch.lifecycle:extensions:1.1.1"
to
api "android.arch.lifecycle:extensions:1.1.1"
In your main build.gradle file
allprojects {
...
configurations {
all {
resolutionStrategy {
force "android.arch.lifecycle:runtime:1.1.1"
}
}
}
}
This will enforce version 1.1.1
Apparently support-v4 was causing the conflict. In the case of this question, the Gradle dependency task wasn't working correctly, but for anyone else who runs into this issue:
./gradlew :app:dependencies will show the sub-dependencies used by your dependencies. Search the output of this command (changing app for your module name) for the dependency causing the conflict.
#RedBassett is right. However I was still having some problem excluding android.arch.lifecycle related sub dependencies.
In my case the conflict was caused in com.android.support:appcompat-v7:27.1.1.
This is how my gradle dependency looks like after excluding it.
implementation ('com.android.support:appcompat-v7:27.1.1') {
exclude group: 'android.arch.lifecycle'
}
api "android.arch.lifecycle:runtime:1.1.1"
kapt "android.arch.persistence.room:compiler:1.1.1"
Also, you will have to add this exclude in every imported module.
I searched for all dependencies with ./gradlew :app:dependencies as #RedBassett mentioned. I noticed the incompatible version of android.arch.core:runtime that Gradle was complaining about was stemming from my version of com.android.support:appcompat-v7, so I just updated that version to the latest and everything worked.
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