I have watched and read many tutorial on How to use Room persistence library with coroutines but whenever I use coroutine in my file it forces me to annotate my code with #InternalCoroutineApi but in the tutorial they don't need to annotate anything.
Now I'm wanted to know
1. What does this annotation means?
2. Why it is necessary?
3. How can I avoid this?
Even this answer doesn't help me either.
below is the how I created my data base and my build.gradle file
import android.content.Context
import androidx.room.Database
import androidx.room.Entity
import androidx.room.Room
import androidx.room.RoomDatabase
import kotlinx.coroutines.InternalCoroutinesApi
import kotlinx.coroutines.internal.synchronized
#Database(entities = [Post::class], version = 1, exportSchema = false)
public abstract class PostRoomDatabase: RoomDatabase() {
abstract fun getDao(): PostDao
companion object{
//Companion object provide the same functionality as the Static keyword in java
#Volatile
private var DATABASE_INSTANCE :PostRoomDatabase? = null
#InternalCoroutinesApi
fun getDatabase(context: Context) : PostRoomDatabase{
val tempInstance = DATABASE_INSTANCE
if(tempInstance != null){
return tempInstance
}
synchronized(this){
val instance = Room.databaseBuilder(
context.applicationContext,
PostRoomDatabase::class.java,
"post_database"
).build()
DATABASE_INSTANCE = instance;
return instance
}
}
}
}
Build.gradle file
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 28
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "vijay.bhadolia.seed"
minSdkVersion 23
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
// To inline the bytecode built with JVM target 1.8 into
// bytecode that is being built with JVM target 1.6. (e.g. navArgs)
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
}
dependencies {
def room_version = "2.2.5"
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.2.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.navigation:navigation-fragment:2.2.2'
implementation 'androidx.navigation:navigation-ui:2.2.2'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'androidx.navigation:navigation-fragment-ktx:2.2.2'
implementation 'androidx.navigation:navigation-ui-ktx:2.2.2'
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
//Circular images
implementation 'de.hdodenhof:circleimageview:3.1.0'
//Room database
implementation "androidx.room:room-runtime:$room_version"
kapt "androidx.room:room-compiler:$room_version"
def coroutines_version = "1.3.0"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"
}
Your imports say:
import kotlinx.coroutines.internal.synchronized
Which is the internal API that it is complaining about. You should not be importing anything for the synchronized keyword, so simply remove that import line.
Related
I'm new learning Kotlin and I'm developing a Notes app to practise with databases and viewModels.
I'm having trouble generating my database and the app crashes when it should generate the database and shows me this error on the logcat:
"java.lang.RuntimeException: cannot find implementation for com.example.blocnotas.database.AppDatabase. AppDatabase_Impl does not exist"
This is how I made my Database class:
package com.example.blocnotas.database
import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
#Database(entities = [Notes::class], version = 1, exportSchema = false)
abstract class AppDatabase: RoomDatabase() {
abstract fun noteDao(): NoteDao
companion object {
#Volatile
private var INSTANCE: AppDatabase? = null
fun getDatabase(context: Context): AppDatabase {
return INSTANCE ?: synchronized(this) {
val instance = Room.databaseBuilder(
context.applicationContext,
AppDatabase::class.java,
"app_notes_database")
.build()
INSTANCE = instance
return instance
}
}
}
My Application class:
package com.example.blocnotas
import android.app.Application
import com.example.blocnotas.database.AppDatabase
class NotesApplication : Application() {
val database: AppDatabase by lazy { AppDatabase.getDatabase(this) }
}
My app gradle:
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'kotlin-kapt'
//id 'androidx.navigation.safeargs.kotlin'
}
android {
namespace 'com.example.blocnotas'
compileSdk 32
defaultConfig {
applicationId "com.example.blocnotas"
minSdk 19
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
viewBinding true
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.navigation:navigation-fragment-ktx:2.5.2'
implementation 'androidx.navigation:navigation-ui-ktx:2.5.2'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1'
implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"
// optional - Kotlin Extensions and Coroutines support for Room
implementation "androidx.room:room-ktx:$room_version"
}
Does anybody know how can i fix it and generate my database table?
I leave you the gitHub repository where i'm making it so if it can help get any extra necessary information: https://github.com/R3inbow/BlocNotasApp.git
I finally solved it changing in the gradle the "kapt" for "ksp" this way:
In dependencies:
ksp "androidx.room:room-compiler:$room_version"
In plugins:
id 'com.google.devtools.ksp' version '1.7.20-1.0.6'
Please help. I use room. But I have such a mistake. If you remove this code
#Database(
entities = [Current::class],
version = 1
)
But I definitely need it to be in my code otherwise everything will be wrong.
This my ForecastDatabase.kt
package com.ggenius.whattowearkotlin.data.db
import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.ggenius.whattowearkotlin.data.db.entity.Current
#Database(
entities = [Current::class],
version = 1
)
abstract class ForecastDatabase : RoomDatabase() {
abstract fun currentWeatherDao(): CurrentWeatherDao
companion object {
#Volatile private var instance: ForecastDatabase? = null
private val LOCK = Any()
operator fun invoke(context: Context) = instance ?: synchronized(LOCK) {
instance ?: buildDatabase(context).also { instance = it }
}
private fun buildDatabase(context: Context) =
Room.databaseBuilder(context.applicationContext,
ForecastDatabase::class.java, "forecast.db")
.build()
}
}
Its my gradle. Check Room
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-android-extensions'
id 'kotlin-kapt'
id 'androidx.navigation.safeargs'
}
android {
compileSdk 31
defaultConfig {
applicationId "com.ggenius.whattowearkotlin"
minSdk 21
targetSdk 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//noinspection GradleDependency
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.4.1'
// Navigation
implementation "android.arch.navigation:navigation-fragment:$navigation_version"
implementation "android.arch.navigation:navigation-ui:$navigation_version"
implementation "android.arch.navigation:navigation-fragment-ktx:$navigation_version"
implementation "android.arch.navigation:navigation-ui-ktx:$navigation_version"
implementation "androidx.core:core-ktx:1.7.0"
implementation "androidx.constraintlayout:constraintlayout:2.1.3"
// Room
//noinspection GradleDependency
implementation "androidx.room:room-runtime:2.4.0-beta01"
implementation "androidx.legacy:legacy-support-v4:1.0.0"
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0'
kapt "androidx.room:room-compiler:$room_version"
// Gson
implementation "com.google.code.gson:gson:2.8.6"
// Kotlin Android Coroutines
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0'
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0"
// Retrofit
implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"
implementation 'com.jakewharton.retrofit:retrofit2-kotlin-coroutines-adapter:0.9.2'
// ViewModel
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
//noinspection GradleDependency
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
//noinspection LifecycleAnnotationProcessorWithJava8
kapt "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"
// Kodein
implementation "org.kodein.di:kodein-di-generic-jvm:$kodein_version"
implementation "org.kodein.di:kodein-di-framework-android-x:$kodein_version"
// Better dateTime-time support even on older Android versions
implementation "com.jakewharton.threetenabp:threetenabp:1.1.0"
// Glide
implementation 'com.github.bumptech.glide:glide:4.11.0'
kapt 'com.github.bumptech.glide:compiler:4.11.0'
// Groupie RecyclerView
implementation 'com.xwray:groupie:2.7.0'
implementation 'com.xwray:groupie-kotlin-android-extensions:2.7.0'
// Preference
implementation "androidx.preference:preference:1.1.1"
// WeatherLocation
implementation "com.google.android.gms:play-services-location:19.0.1"
// New Material Design
implementation "com.google.android.material:material:1.5.0"
//test
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
In this screenshot, there is an error due to which my application does not start
enter image description here
You don't appear to have implementation 'androidx.room:room-ktx:2.4.0' in the build gradle.
This is what I'm seeing when I try to build my project. I haven't changed anything except what Android forced me to in the Manifest and I don't know where to go after this.
Dao
#Dao
interface SubscriberDAO {
#Insert
suspend fun insertSubscriber(subscriber: Subscriber): Long
#Update
suspend fun updateSubscriber(subscriber: Subscriber): Int
#Delete
suspend fun deleteSubscriber(subscriber: Subscriber): Int
#Query("DELETE FROM subscriber_data_table")
suspend fun deleteAll(): Int
#Query("SELECT * FROM subscriber_data_table")
fun getAllSubscribers(): LiveData<List<Subscriber>>
}
What is wrong?
I tried to change the TargetSdk back to 30 and it still didn't work
Gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 31
defaultConfig {
applicationId "com.homeofficeprojects.samplearchitecturedatabasecoroutinesproject"
minSdkVersion 21
targetSdkVersion 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
buildFeatures{
dataBinding = true
// for view binding :
// viewBinding = true
}
/*dataBinding{
enabled = true
}*/
}
dependencies {
def lifecycle_version = "2.4.0"
def room_version = "2.3.0"
kotlin {
experimental {
coroutines "enable"
}
}
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
// ViewModel
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
// LiveData
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
// Annotation processor
implementation("androidx.room:room-runtime:$room_version")
// To use Kotlin annotation processing tool (kapt)
kapt("androidx.room:room-compiler:$room_version")
// optional - Kotlin Extensions and Coroutines support for Room
implementation("androidx.room:room-ktx:$room_version")
annotationProcessor("androidx.room:room-compiler:$room_version")
//coroutines
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation 'androidx.cardview:cardview:1.0.0'
}
Subscriber
package com.homeofficeprojects.samplearchitecturedatabasecoroutinesproject
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
#Entity(tableName = "subscriber_data_table")
data class Subscriber(
#PrimaryKey(autoGenerate = true)
#ColumnInfo(name = "subscriber_id")
var id: Int,
#ColumnInfo(name = "subscriber_name")
var name: String,
#ColumnInfo(name = "subscriber_email")
var email: String
) {
//constructor(): this(0, "", "")
}
Edit: I've added the Gradle Build file and Subscriber
kotlin class
Edit 2: Second picture, more info on the errors
I ended up asking on reddit and was told to roll back the gradle dependency.
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
from
ext.kotlin_version = "1.6.0"
to
ext.kotlin_version = "1.5.31"
I'm not sure I would call that a way forward, but I can move on with my project so I'm calling it one until an actual answer comes through
I am trying to call a suspend function using viewModelScope.launch in which "launch" is showing as Unresolved reference.
Here is build.gradle
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
}
android {
compileSdk 31
defaultConfig {
applicationId "com.example.mynotes"
minSdk 27
targetSdk 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
packagingOptions {
exclude 'META-INF/atomicfu.kotlin_module'
}
}
dependencies {
implementation "androidx.appcompat:appcompat:$rootProject.appCompatVersion"
implementation "androidx.activity:activity-ktx:$rootProject.activityVersion"
// Dependencies for working with Architecture components
// You'll probably have to update the version numbers in build.gradle (Project)
// Room components
implementation "androidx.room:room-ktx:$rootProject.roomVersion"
kapt "androidx.room:room-compiler:$rootProject.roomVersion"
androidTestImplementation "androidx.room:room-testing:$rootProject.roomVersion"
// Lifecycle components
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$rootProject.lifecycleVersion"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$rootProject.lifecycleVersion"
implementation "androidx.lifecycle:lifecycle-common-java8:$rootProject.lifecycleVersion"
// Kotlin components
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
api "org.jetbrains.kotlinx:kotlinx-coroutines-core:$rootProject.coroutines"
api "org.jetbrains.kotlinx:kotlinx-coroutines-android:$rootProject.coroutines"
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0'
// UI
implementation "androidx.constraintlayout:constraintlayout:$rootProject.constraintLayoutVersion"
implementation "com.google.android.material:material:$rootProject.materialVersion"
// Testing
testImplementation "junit:junit:$rootProject.junitVersion"
androidTestImplementation "androidx.arch.core:core-testing:$rootProject.coreTestingVersion"
androidTestImplementation ("androidx.test.espresso:espresso-core:$rootProject.espressoVersion", {
exclude group: 'com.android.support', module: 'support-annotations'
})
androidTestImplementation "androidx.test.ext:junit:$rootProject.androidxJunitVersion"
}
and the ViewModel.kt
package com.example.mynotes
import android.app.Application
//import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.LiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.*
class NotesViewModel(application: Application) : ViewModel() {
private val repository : NotesRepository
val allNotes : LiveData<List<Notes>>
init {
val dao = NotesDatabase.getDatabase(application).getNotesDao()
repository = NotesRepository(dao)
allNotes = repository.allNotes
}
fun deleteNotes(notes: Notes) = viewModelScope.launch(Dispatchers.IO) {
repository.delete(notes)
}
}
In the function deleteNotes "viewModelScope.launch" is showing Unresolved reference: launch but there is no error while building the app but my app crash while running.
I think it's because of the way you are declaring the variable, since you are declaring it as a direct function, you can try the following:
fun deleteNotes(notes: Notes) {
viewModelScope.launch(Dispatchers.IO) {
repository.delete(notes)
}
}
It's possible the issue is related that when the method is declared and stored in memory, the scope hasnt been assigned yet.
Which version are you using?
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.3.1"
Try to use this case is different.
Try to invalide cache and restart if still not recognized
I am trying to write the following unit test for a function in my project
import android.content.Context
import org.junit.Test
import androidx.test.core.app.ApplicationProvider
import com.adi_random.tracky.api.searchBook
import com.adi_random.tracky.models.GoodreadsBook
import com.google.gson.Gson
import okhttp3.Call
import okhttp3.Callback
import okhttp3.Response
import java.io.IOException
import com.google.common.truth.Truth.assertThat
/**
* Created by meadi on 6/27/2020.
*/
class BookFetchTest {
/**
* Test if the Tracy API searchBook endpoint returns the expected result and gets parsed correctly
*/
val context = ApplicationProvider.getApplicationContext<Context>()
#Test
fun bookFetchResultValidation() {
val query = "Dune";
searchBook(query, context, object : Callback {
override fun onFailure(call: Call, e: IOException) {
TODO("Not yet implemented")
}
override fun onResponse(call: Call, response: Response) {
val gson = Gson();
val res = gson.fromJson<Array<GoodreadsBook>>(
response.body?.charStream(),
Array<GoodreadsBook>
::class.java
)
assertThat(res).hasLength(20);
}
})
}
}
When hitting run, I am getting Unresolved reference in :app:compileDebugUnitTestKotlin gradle task for the following dependencies: test (double clicking the error highlights androidx.test.core.app.ApplicationProvider), common ( in com.google.common.truth.Truth.assertThat), ApplicationProvider ( in ApplicationProvider.getApplicationContext()) and assertThat (in the assertThat call at the end of the test).
Here is my module build.gradle file:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
buildFeatures {
viewBinding true
}
testOptions {
unitTests.includeAndroidResources = true
}
defaultConfig {
applicationId "com.adi_random.tracky"
minSdkVersion 23
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
useLibrary 'android.test.runner'
useLibrary 'android.test.base'
useLibrary 'android.test.mock'
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.squareup.okhttp3:okhttp:4.1.0'
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.navigation:navigation-fragment-ktx:2.1.0'
implementation 'androidx.navigation:navigation-ui-ktx:2.1.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.ext:truth:1.2.0'
androidTestImplementation 'com.google.truth:truth:0.42'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation 'androidx.test:core:1.2.0'
// AndroidJUnitRunner and JUnit Rules
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test:rules:1.2.0'
}
As you can see I have those dependencies added to my gradle build file with the androidTestImplementation directive, so I don't understand why those errors get thrown. Does anyone have any idea? Thanks in advance!
Edit:Here is a screenshot of the problem:
Add this dependency:
def androidx_test_core = "1.2.0"
androidTestImplementation "androidx.test:core-ktx:$androidx_test_core"
def androidx_test_ext = "1.1.1"
androidTestImplementation "androidx.test.ext:junit-ktx:$androidx_test_ext"
def hamcrestVersion = '2.2'
testImplementation "org.hamcrest:hamcrest:$hamcrestVersion"