Unresolved reference: viewModelScope - Kotlin Android - android

I try to add viewModelScope to a basic viewModel but android studio doesn't recognize it.
I tried to change my gradle build file with some solution I found but nothing works.
Here an extract of my build.gradle app
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0-alpha01"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.2.0-alpha01"
implementation "androidx.lifecycle:lifecycle-viewmodel-savedstate:1.0.0-alpha01"
kapt "androidx.lifecycle:lifecycle-compiler:2.2.0-alpha01"
When I type viewModelScope in my viewModel it say Unresolved reference: viewModelScope.

for now its in alpha, so please update your gradle to use the following dependencies:
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0"

In my case i forgot to extends ViewModel in that class, the class you use for viewModelScope must be like yourModelClass : ViewModel() in kotlin and for java yourModelClass extends ViewModel
Hope its help

I've had the same issue and I've just imported:
"androidx.navigation:navigation-fragment-ktx:2.2.0-rc03"
"androidx.lifecycle:lifecycle-livedata-ktx:2.2.0-rc03"
Even though I thought fragment-ktx was not really related. Took me a while to figure that out. Hope it helps!

Also check that you are in the correct file. I had the same problem for a moment and I came to this page, but later on, I realized I accidentally tried to run viewModelScope.launch on my Fragment.
viewModelScope.launch is only available in your ViewModels and
lifecycleScope.launch in your lifecycle aware components.

For latest version of the artifact refer
Maven Repository Android Lifecycle ViewModel Kotlin Extensions
In app level build.gradle file add the following :-
def lifecycle_version = "2.2.0-rc03"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
kapt "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"
Don't forget to add apply plugin: 'kotlin-kapt' at the top of app/build.gradle file

viewModelScope was introduced with release 2.1.0, see here.
Check whether lifecycle-viewmodel-ktx-2.2.0-alpha01.aar is installed. For me there is no error message with the settings you wrote. However, there is an error message when using an earlier version:
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.0.0"
But this works:
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.1.0"

Maybe you are not extending the activityViewModel with ViewModel class
class SampleActivityViewModel: ViewModel() {
fun getData(){
viewModelScope.launch{
// Make an API call
}
}
}

Remove below config from build.gradle(:app)
configurations {
all {
exclude group: 'androidx.lifecycle', module: 'lifecycle-viewmodel-ktx'
}
}

It looks like you've got two different versions of the androidX lifecycle libraries in use.
Change your app/build.gradle to be:
...
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0-alpha01"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.2.0-alpha01"
implementation "androidx.lifecycle:lifecycle-viewmodel-savedstate:2.2.0-alpha01"
kapt "androidx.lifecycle:lifecycle-compiler:2.2.0-alpha01"
...

ViewModelScope only added in version 2.2.0, not available on higher versions too. I tried with 2.6.0 but got same error.

In Build.gradle (App Level)
Change your code from:
def lifecycle_version = "2.0.0" or if you are using any lower version than this to:
def lifecycle_version = "2.2.0"
viewModelScope was launched in 2.2.0 version of lifecycle module so you won't find it before that.

Related

CreationExtras must have a value by `SAVED_STATE_REGISTRY_OWNER_KEY`

I'm trying to implement navigation in my app which is built with Jetpack Compose, but when I try to navigate from a screen to another I get:
java.lang.IllegalArgumentException: CreationExtras must have a value by SAVED_STATE_REGISTRY_OWNER_KEY
I'm using:
implementation "androidx.hilt:hilt-navigation-compose:1.0.0"
And here is the code:
if(viewModel.isAuthenticated) {
navController.navigate(Screen.Profile.route)
}
#Dragan.T 's answer is correct.
Adding
implementation "androidx.navigation:navigation-compose:2.5.1"
Solved my problem. As for why we need to add, I am not so sure.
If you use Compose with Fragments, then you may not have the Fragments dependency where viewModels() is defined.
Adding:
implementation "androidx.fragment:fragment-ktx:1.5.2"
to my build.grade script fixed it for me (previously this was a transitive dependency).
Hilt release notes for 2.43 flags a dependency incompatibility:
As part ViewModel bug fixes, dependencies were updated as below. androidx.navigation users will need to update to 2.5.0 to interoperate. These libraries require building with SDK 31. To build with SDK 31, AGP users will need to use AGP 7.0+. This will also require using JDK11.
androidx.activity and androidx.fragment to 1.5.0
androidx.lifecycle to 2.5.0
androidx.savedstate to 1.2.0
Insert implementation "androidx.navigation:navigation-compose:2.5.1" into your gradle file. If you already have it, be sure it's updated with the latest (2.5.1) version.
In my case I had to upgrade two dependencies: Hilt and androidx.navigation. The curious issue is that after upgrading it, the error is gone, but if I downgrade again to previous versions, the error doesn't appear again. These are the dependencies I changed:
navigation_version = "2.5.3" // was 2.5.1
dagger_hilt_version = "2.44.2" // was 2.43.2
implementation "androidx.navigation:navigation-fragment-ktx:$navigation_version"
implementation "androidx.navigation:navigation-ui-ktx:$navigation_version"
implementation "androidx.navigation:navigation-dynamic-features-fragment:$navigation_version"
androidTestImplementation "androidx.navigation:navigation-testing:$navigation_version"
implementation "com.google.dagger:hilt-android:$dagger_hilt_version"
kapt "com.google.dagger:hilt-android-compiler:$dagger_hilt_version"
testImplementation "com.google.dagger:hilt-android-testing:$dagger_hilt_version"
kaptTest "com.google.dagger:hilt-android-compiler:$dagger_hilt_version"
androidTestImplementation "com.google.dagger:hilt-android-testing:$dagger_hilt_version"
kaptAndroidTest "com.google.dagger:hilt-android-compiler:$dagger_hilt_version"
This issue is resolved by updating to version 1.1.0-alpha01 of the hilt navigation compose library.
You can to continue use this library:
androidx.hilt:hilt-navigation-compose:1.0.0
Only you are sure that ViewModel is initialized in a Composable that is root in your activity.
For example:
setContent {
AndroidLearningTheme {
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colors.background
) {
HeroesScreen()
}
}
}
Your Composable
#Composable
fun HeroesScreen(
viewModel: HeroesViewModel = hiltViewModel()
)

Problem duplicate class androidx.lifecycle.viewmodel found in modules

I got these errors when I try to run the emulator
Duplicate class androidx.lifecycle.ViewModelLazy found in modules jetified-lifecycle-viewmodel-ktx-2.3.1-runtime (androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1) and lifecycle-viewmodel-2.4.0-runtime (androidx.lifecycle:lifecycle-viewmodel:2.4.0)
Duplicate class androidx.lifecycle.ViewModelProviderKt found in modules jetified-lifecycle-viewmodel-ktx-2.3.1-runtime (androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1) and lifecycle-viewmodel-2.4.0-runtime (androidx.lifecycle:lifecycle-viewmodel:2.4.0)
Duplicate class androidx.lifecycle.ViewTreeViewModelKt found in modules jetified-lifecycle-viewmodel-ktx-2.3.1-runtime (androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1) and lifecycle-viewmodel-2.4.0-runtime (androidx.lifecycle:lifecycle-viewmodel:2.4.0)
Note: This is not specific to the android emulator but problem with gradle build.
Most likely, one of your dependencies uses the kotlin version of the viewmodel library whereas your code uses the java version.
Specify both to enforce the latest version for all dependencies:
def lifecycle_version = "2.4.0"
implementation "androidx.lifecycle:lifecycle-viewmodel:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
I had the same problem and I solved it by adding only one line of code
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0'
Changing the viewmodel and viewmodel-ktx version to their latest version solved the problem for me :
implementation "androidx.lifecycle:lifecycle-viewmodel:2.5.1"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1"
I thought that eliminating duplicate classes is better than adding new ones, so I'll post my solution to this problem here:
configurations {
all {
exclude group: 'androidx.lifecycle', module: 'lifecycle-viewmodel-ktx'
}
}
These lines of code need to be added to the project level build.gradle file - and the build error will go away along with the wasted memory (a bit, but still).
Strange and incomprehensible behavior. I got it after adding the Kotlin library to the project, which it was later decided to replace with a version for Java. If you go to the .gradle folder, you can find it there, but I'm not sure if removing it from there is a good idea, because it may be used in other libs. It is strange that gradle or AndroidStudio does not automatically solve this problem, because only dependencies for Java are specified in the build.gradle file.
PROBLEM: I got this error when I updated the appcompat dependency to 1.5.1.
SOLUTION: I updated the appcompat dependency to 1.6.1.
// Pick one:
// Kotlin
implementation("androidx.appcompat:appcompat:1.6.1")
// Groovy
implementation "androidx.appcompat:appcompat:1.6.1"
REASON: This works because of a bug fix implemented in 1.6.0-beta01 - therefore later versions should also work.
The 1.6.0-beta01 release notes state the following in the "Bug Fixes" section:
AppCompat now explicitly depends on Lifecycle 2.5.1 and SavedState 1.2.0. (I7e3e2)
It helped me reverting appcompat from 1.5.0 to 1.4.2 as suggested in this thread: Duplicate class androidx.lifecycle.ViewModelLazy found in modules lifecycle-viewmodel-2.5.0-runtime
I get the same error, any answers solved my issue. The key point is here to solve the error (preferences 1.2.0 in my project -> add exclude group).
def preference_version = "1.2.0"
implementation ("androidx.preference:preference:$preference_version"){
exclude group: 'androidx.lifecycle', module:'lifecycle-viewmodel'
exclude group: 'androidx.lifecycle', module:'lifecycle-viewmodel-ktx'
}
Then use 2.5.1 version for lifecycle dependencies.
def lifecycle_version = "2.5.1"
// ViewModel
implementation "androidx.lifecycle:lifecycle-viewmodel:$lifecycle_version"
// LiveData
implementation "androidx.lifecycle:lifecycle-livedata:$lifecycle_version"
// Lifecycles only (without ViewModel or LiveData)
implementation "androidx.lifecycle:lifecycle-runtime:$lifecycle_version"
// https://developer.android.com/jetpack/androidx/releases/lifecycle
implementation "androidx.lifecycle:lifecycle-viewmodel-savedstate:$lifecycle_version"
This is working fine, i hope that it will help some people !
for anyone using compose,
you just need to add
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:2.5.1"
While many of these answers will work, there is a better way to set transitive dependency versions rather than including the package as a direct dependency.
constraints {
implementation('androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1') {
because 'insert explanation here'
}
}
Here's a breakdown https://docs.gradle.org/current/userguide/dependency_constraints.html
As directed by l33t, I added
def lifecycle_version = "2.5.1"
implementation "androidx.lifecycle:lifecycle-viewmodel:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
but put the lines in the wrong file and got
Could not find method implementation() for arguments...
Solution: Make sure you're adding these dependencies in android/app/build.gradle, not android/build.gradle. See here.
After creating a new empty Compose activity, I got this error.
Update all dependencies to the latest version solve error with Duplicate class androidx.lifecycle.ViewModelLazy ...
Simple solution add this dependence
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0'

Cannot resolve symbol ViewModelProviders

I am working on Android ViewModel architecture component but I am getting the above mentioned error when trying to initialize a ViewModel in an AppCompatActivity.
import android.arch.lifecycle.ViewModelProviders;
ViewModelProviders.of(this).get(CounterViewModel.class);
There are a few questions and articles related to this, and they pointed towards adding the lifecycle:extensions and lifecycle:viewmodel dependencies in the app gradle file, but I am still getting the error.
implementation "android.arch.lifecycle:extensions:1.1.1"
implementation "android.arch.lifecycle:viewmodel:1.1.1"
annotationProcessor "android.arch.lifecycle:compiler:1.1.1"
The package android.arch.lifecycle does not contain the class ViewModelProviders and it only has ViewModelProvider class.
What else needs to be added to access the ViewModelProviders class?
Edit :
Dependencies in app/build.gradle:
dependencies {
implementation project(':lifecycle')
implementation project(':base')
implementation "android.arch.lifecycle:extensions:1.1.1"
implementation "android.arch.lifecycle:viewmodel:1.1.1"
annotationProcessor "android.arch.lifecycle:compiler:1.1.1"
}
android.arch.lifecycle:extensions:1.1.1 definitely has android.arch.lifecycle.ViewModelProviders. You can see it in Android Studio, if you open the "External Libraries" portion of the project tree and examine the library contents:
Some possible reasons for not finding the import include:
You have implementation "android.arch.lifecycle:extensions:1.1.1" in the wrong place (it should be in the dependencies closure of the module's build.gradle file, such as app/build.gradle)
You did not sync Android Studio with the Gradle build files (you are normally prompted to do this, but you can do it manually from File > Sync Project with Gradle Files from the Android Studio main menu)
You do not need both lifecycle:extensions and lifecycle:viewmodel in your build.gradle file, remove
implementation "android.arch.lifecycle:viewmodel:1.1.1"
and it should be fine now. Also, you may want to migrate to AndroidX and use the 2.0.0 versions of the library.
ViewModelProviders is now deprecated. Use ViewModelProvider instead.
If you are configuring in libary, you can modify the implementation to api

ViewModel in Kotlin: Unresolved Reference

I am trying to implement ViewModel in a 100% Kotlin app. Every piece of documentation I can find says I want to use this to get the ViewModel instance:
ViewModelProviders.of(this).get(CustomViewModel::class.java)
According to the docs, I should be able to import this with:
import android.arch.lifecycle.ViewModelProviders
This import is unresolved though. I am using the following in my build file:
def androidArchVersion = '1.1.1'
implementation "android.arch.lifecycle:viewmodel:$androidArchVersion"
implementation "android.arch.lifecycle:livedata:$androidArchVersion"
annotationProcessor "android.arch.lifecycler:compiler:$androidArchVersion"
testImplementation "android.arch.core:core-testing:$androidArchVersion"
Why can't I access ViewModelProviders?
Include the following as a dependency:
implementation "android.arch.lifecycle:extensions:1.1.1"
The equivalent AndroidX dependency is:
"androidx.lifecycle:lifecycle-extensions:VERSION"
in where VERSION can be replaced for Current Stable, Beta or Alpha values given in this official link
This dependency is for both ViewModel and LiveData and thus would not require you to give separate dependencies for the same either; i.e. the first two dependencies indicated by you can be replaced by the aforementioned lifecycle extensions dependency.
In my case I was missing :
implementation "androidx.fragment:fragment-ktx:1.1.0"
In addition to what Sup suggested, you'll have to correct lifecycler:compiler to lifecycle:compiler - the Gradle sync shouldn't even complete successfully with this typo.
Secondly, the standard android annotation processing ("annotationProcessor") doesn't really work with Kotlin. Instead, use Kotlin's kapt.
At the top of your build.gradle file, add the following:
apply plugin: 'kotlin-kapt'.
And in your dependencies section, replace occurences of annotationProcessor (like the above one) with kapt, e.g.
kapt "android.arch.lifecycle:compiler:1.1.1"
ViewModelProviders is deprecated in 1.1.0
Check this android docs
https://developer.android.com/topic/libraries/architecture/viewmodel
I am using 2.3.1 and add below dependency in build.gradle
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
Declare ViewModel in your Kotlin code as per below:
private val cartViewModel: CartViewModel by viewModels()
Still, if you facing below error like
Unresolved reference: viewModels
Then need to add below below dependency in build.gradle
implementation 'androidx.lifecycle:lifecycle-extensions-ktx:2.2.0'
implementation 'androidx.activity:activity-ktx:1.4.0'
implementation 'androidx.fragment:fragment-ktx:1.3.6'
OR
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.5'
I solve this by doing like this.
implement this dependency
implementation "android.arch.lifecycle:extensions:1.1.1"
then call my ViewModel class
homeViewModel = ViewModelProvider(this).get(HomeViewModel::class.java)
I faced this kind of problem in AndroidStudio 3.0.1 and solved by adding
following dependencies in the proper build.gradle:
implementation "android.arch.lifecycle:extensions:1.1.1"
annotationProcessor "android.arch.lifecycle:compiler:1.1.1"
version code may be different as AndroidStudio tells you if it differs.
If the above "adding/updating dependecies" did not resolve your issue then try to restart your android studio. It´s just to root, I do not see any major issue with it. Hope it helps.
Resolved with this dependency for me
implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
If someone want androidx, then, first - in build.gradle (app):
implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
Second - in file with code:
import androidx.lifecycle.ViewModelProvider
And third - use it:
ViewModelProvider(this).get(CustomViewModel::class.java)
Or use it like this (if needed ViewModelFactory):
ViewModelProvider(this, CustomViewModelFactory).get(CustomViewModel::class.java)
Not really sure why there are soo many solutions to this problem however while none of these worked for me, I did find a solution in my case.
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.4.1"
This can also be resolved by targeting minSdkVersion to 21.
If you have minSdkVersion 21 or higher, you won't need implementation "android.arch.lifecycle:extensions:1.1.1".
android {
kotlinOptions {
jvmTarget = '1.8'
}
}
project e app level

Error:Execution failed for task ':app:kaptDebugKotlin'

I'm new to using Kotlin and trying to set it up with Dagger2, I've seen some few examples but none of them seem to work for me.
I keep getting this
Error:Execution failed for task ':app:kaptDebugKotlin'.
Internal compiler error. See log for more details
I have my build.gradle (Module: app)
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 25
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "com.exampleapp"
minSdkVersion 14
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
kapt {
generateStubs = true
}
dexOptions {
javaMaxHeapSize "2048M"
}
}
ext {
supportLibVer = '25.0.0'
daggerVer = '2.8'
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
// Support lib
compile "com.android.support:appcompat-v7:${supportLibVer}"
kapt "com.google.dagger:dagger-compiler:${daggerVer}"
compile "com.google.dagger:dagger:${daggerVer}"
provided "javax.annotation:jsr250-api:${javaxVer}"
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
}
repositories {
mavenCentral()
}
Run your application with ./gradlew clean build command to see what's exactly wrong with your code. Just paste it into the Terminal in Android Studio.
If you are using the Room database and getting a KAPT error, just check your
Database declarations
Data Access Object declarations
Data class fields
It's a problem arising due to improper usage of annotations of Room.
For more information use your build logs.
I faced this problem for a while. What helped me a lot was reading the build tab because it gave the reasons the library was failing.
Here is the tab
I had many problems,
1. I haven't added the new entity I created into the #Database annotation
2. I haven't added the #Dao annotation in my interface
3. I haven't updated some variables names that was wrote in a #Query annotation
So I had to kill problem by problem, finally it could run later.
In Addition, I was cleaning my project and rebuilding to ensure code doesn't get stuck. Also close and open Android Studio.
Futhermore, you can check this answer to help you find the error enable more log on error
In my case I replaced this
implementation 'com.google.dagger:dagger:2.27'
kapt 'com.google.dagger:dagger-compiler:2.27'
by
implementation 'com.google.dagger:dagger:2.27'
annotationProcessor "com.google.dagger:dagger-compiler:2.27"
and solved the problem
I faced this problem for a while. My mistake was using private access specifier with #Inject field.
If you are using Dagger then check for #Inject private fields or to know the exact cause add this as Command-line options:
--stacktrace --info --scan
On Mac, go to Android Studio > Preferences > Build, Execution, Deployment > Compiler
On Windows, go to File > Settings > Build, Execution, Deployment > Compiler
In my case, I forgot to add the room db entities to the database
#Database(version = 1,
entities = [DummyEntity::class]
)
Issue can be connected with Room and Kotlin 1.4.10.
Try to change android.arch.persistence to androidx.room for Room dependencies:
Use
kapt "androidx.room:room-compiler:$roomVersion"
instead of
kapt "android.arch.persistence.room:compiler:$roomVersion"
If You are using Hilt and Field Injection Then Remove Private From Field Injected Object this worked For me
#Inject
private lateinit var helper: Helper
to
#Inject
lateinit var helper: Helper
Worked for me:
I also had the same problem and solved it by adding this to gradle.properties
org.gradle.java.home=<go to project structure, copy JDK location and past here>
This ensures that gradlew uses the same JDK as Android Studio
The issue is probably related to the use of Room. I used the command Łukasz Kobyliński suggested in his comment
./gradlew clean build
and in my case I had to add a converter for Date type.
You can find the converter in the official docs: https://developer.android.com/training/data-storage/room/referencing-data#type-converters
I have solved this problem. In my case, there were irrelevant dagger
dependencies
that the IDE did not notify me about:
implementation 'com.google.dagger:dagger:2.35.1'
kapt 'com.google.dagger:dagger-compiler:2.28'
After updating them, the problem disappeared and it became possible to use the
latest version of Kotlin!
implementation 'com.google.dagger:dagger:2.37'
kapt 'com.google.dagger:dagger-compiler:2.37'
Just Replace kept Keyword to annotationProcessor and everything works fine.
my mistake was using suspend when then function returns LiveData.Room's coroutines integration brings ability to return suspend values but when the value itself is asnyc, there is no reason to use it.
i changed :
#Delete
suspend fun Delete(premiumPackageDBEntity: PremiumPackageDBEntity)
#Query("SELECT * FROM available_premium_package ")
suspend fun GetAll(): LiveData<List<PremiumPackageDBEntity>>
to :
#Delete
suspend fun Delete(premiumPackageDBEntity: PremiumPackageDBEntity)
#Query("SELECT * FROM available_premium_package ")
fun GetAll(): LiveData<List<PremiumPackageDBEntity>>
and the problem solved.
In my case, I forgot to add newly created entities into "entities" section of #Database declaration using Room library.
--stacktrace --info --scan commandline options are a great help to find the exact cause.
I just faced a similar bug. If you're using an old dependency for Room, update and rebuild your project.
I faced similar problem when setting up dagger2. It was finally resolved when I changed this line:
kapt "com.google.dagger:dagger-compiler:${daggerVer}"
to this
annotationProcessor "com.google.dagger:dagger-compiler:${daggerVer}"
For me I deleted these folders.
.gradle
.idea
Close android studio , delete the folders and reopen the project
//implementation "androidx.room:room-runtime:2.4.2"
kapt "androidx.room:room-compiler:2.2.1"
//kapt "android.arch.persistence.room:compiler:2.4.2"
implementation "androidx.room:room-ktx:2.2.1"
//annotationProcessor "androidx.room:room-compiler:2.4.2"
I didn't use the ones I used. My problem was solved when I used these two. We get a kaptDebug error because there is no match with the Room. My problem was related to the implement.
if all that tasks are not work, just run your app. You will see error log clearly.
First change
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
to
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
Now you have to tweak your project Gradle file and update the version of Kotlin being used which should be something like below:
ext {
kotlin_version = '1.3.10'
gradleVersion = '3.1.0'
}
I got the same error and solved it simply by following these steps
1- open File menu -> then choose Project Structure or press Ctrl+Alt+Shift+s
2- open Modules from the left
3- In Source Compatibility press the drop down menu and choose Java 8 or 1.8
4- In Target Compatibility press the drop down menu and choose Java 8 or 1.8
5- press ok then sync and rebuild your project or run it
In my case build.gradle
replaced
id 'kotlin-android-extensions' to
id 'kotlin-parcelize'
as it said on build
added
buildFeatures {
viewBinding true
}
also had a few syntax mistakes like forgetting : at Dao
#Query("SELECT * FROM table_satis WHERE satisId ==:satisID")
In my case I'm using ViewBinding instead of DataBinding. And when I got the same problem I solved it with adding plugin apply plugin: 'kotlin-parcelize' to gradle.
try add to gradle.properties:
kapt.use.worker.api=false
kapt.incremental.apt=false
I wrote accidentally #EntryPoint instead of #AndroidEntryPoint. Changing that error was fixed.
I faced a similar problem. It was resolved when I changed this line:
ext.kotlin_version = "1.5.10"
to
ext.kotlin_version = "1.4.10"
In some of the Cases if the id of the View is incorrect it always shows this error.Recheck if the id of the view is correct.
In my case, i just updated the recently added dependencies(a newer version was available), and it worked for me.
In my case, I was using
kapt "com.github.bumptech.glide:compiler:$version_glide"
without applying the implementation.
implementation "com.github.bumptech.glide:glide:$version_glide"
You should check all kapt dependencies in the build.gradle (Module), not just glide
What worked for me was to add all of these dependencies:
room_version = '2.4.3'
// Room
implementation "androidx.room:room-runtime:$room_version"
implementation "androidx.room:room-ktx:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"
implementation "androidx.room:room-rxjava2:$room_version"
kapt "androidx.room:room-compiler:$room_version"

Categories

Resources