I am having a problem where my build cannot find one of the androidx classes, specifically:
androidx.lifecycle.DefaultLifecycleObserver
Here are my gradle deps:
annotationProcessor "androidx.lifecycle:lifecycle-compiler:2.0.0"
implementation "androidx.lifecycle:lifecycle-runtime:2.0.0"
implementation "androidx.lifecycle:lifecycle-extensions:2.0.0"
I don't have any other problems getting androidx classes, just this one.
I have tried to invalidate caches in android studio and restart with no luck. Also a build clean as well as a gradle sync.
I verified here:
https://developer.android.com/jetpack/androidx/migrate
The mapping of that class from the support library to androidx:
android.arch.lifecycle.DefaultLifecycleObserver ->
androidx.lifecycle.DefaultLifecycleObserver
Any ideas on why this is happening?
I think that's because you're missing one dependency:
implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version"
Get the latest version of lifecycle-common-java8 here
See the documentation:
If you use Java 8 Language, then observe events with
DefaultLifecycleObserver. To include it you should add
"androidx.lifecycle:lifecycle-common-java8:" to your
build.gradle file.
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 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.
Error while adding MoshiPack Library in Kotlin latest version 1.3.70 to gradle.build application
Moshi pack
implementation 'com.daveanthonythomas.moshipack:moshipack:1.0.1'
Error Message
Duplicate class kotlin.reflect.KClasses found in modules jetified-kotlin-reflect-1.1.1.jar (org.jetbrains.kotlin:kotlin-reflect:1.1.1) and jetified-kotlin-stdlib-1.3.70.jar (org.jetbrains.kotlin:kotlin-stdlib:1.3.70)
Any suggestions how to solve this issue or any other library I can use in Kotlin so I can use Message Pack.
Thanks in advance
Try to add this to your dependencies:
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
and make sure you specified your Android NDK location under File>Project Structure...>SDK Location
Starting Kotlin 1.3.70 some basic useful members on KClass included in Kotlin standard library (they were in a kotlin-reflect before).
See "Working with KClass" in https://blog.jetbrains.com/kotlin/2020/03/kotlin-1-3-70-released/
In your case MoshiPack adds a kotlin-reflect library that conflicts with standard library.
You should exclude transitive dependency to resolve the conflict.
If you use KotlinDSL, in build.gradle.kts:
implementation ("com.daveanthonythomas.moshipack:moshipack:1.0.1") {
exclude(group = "org.jetbrains.kotlin", module = "kotlin-reflect")
}
If you use Groovy, in build.gradle:
implementation ('com.daveanthonythomas.moshipack:moshipack:1.0.1') {
exclude group: 'org.jetbrains.kotlin', module: 'kotlin-reflect'
}
I tried this and it worked
implementation "org.jetbrains.kotlin:kotlin-reflect:1.4.10"
i think the only way to solve it , to go back to kotlin version 1.3.61 , so remove 1.3.70 and use 1.3.61
So I finally figured it out and here's how :-
So the main problem is you have injected 2 dependency of same class. Here he used 2 dependency for Kotlin which conflict in runtime to fix that you have to check which dependency is duplicated. (It is most case scenario. It can be with any other dependency i.e. Hilt)
Go to File > Project structure > Dependencies
Check which dependency are repeating. In this case it will have (androidx.core:core:1.8.0) and (androidx.core:core:+)
as you can see there are 2 dependency with same classes version 1.8.0 will have all the class which core:+ will have and this is causing a error.
Now delete (androidx.core:core:+) and hit Apply and sync project.
Now you should be good to go. here is structure after changing dependency.
Note:- This method will show all the android dependency which you might be not included but you will see all the dependency which any app has. Please remove the dependency who are you familiar with do not remove any dependency without any proper knowledge.
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 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).