#UiThreadTest Unresolved Reference - android

I need a test to run on the UI thread, so I want to use the UiThreadTest annotation, but it's not resolving that annotation. I'm guessing I have to include a dependency in the gradle file, but I can't for the life of me figure out what it is.
#Test
#UiThreadTest
fun insertMultipleDelete() {
My module's build.gradle dependencies:
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.annotation:annotation:1.1.0'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.0.0'
def nav_version = "2.3.3"
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"
def room_version = "2.2.6"
implementation "androidx.room:room-runtime:$room_version"
implementation "androidx.room:room-ktx:$room_version"
kapt "androidx.room:room-compiler:$room_version"
testImplementation "androidx.room:room-testing:$room_version"
testImplementation 'androidx.test:core:1.3.0'
testImplementation 'junit:junit:4.13.1'
androidTestImplementation "androidx.navigation:navigation-testing:$nav_version"
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
What do I need to do to make it resolve?

Figured it out, you have to include androidTestImplementation 'androidx.test:rules:1.3.0' in your gradle file.
Found it on some German website, thanks for the stellar documentation Google.

Related

cannot use Room database kotlin

I cannot use #Entity, #Dao, #Database.
Error :
enter image description here
This is my implementation :
implementation "androidx.room:room-runtime:2.4.2"
implementation "androidx.room:room-ktx:2.4.2"
kapt "androidx.room:room-compiler:2.4.2"
implementation "androidx.navigation:navigation-fragment-ktx:2.4.1"
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.6.10"
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'androidx.recyclerview:recyclerview:1.3.0-alpha01'
implementation 'androidx.room:room-runtime:2.5.0-alpha01'
implementation 'androidx.navigation:navigation-ui-ktx:2.4.1'
implementation 'androidx.legacy:legacy-support-v4:1.0.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.lifecycle:lifecycle-extensions:2.2.0'
implementation 'androidx.activity:activity-ktx:1.4.0'
compile 'androidx.constraintlayout:constraintlayout:2.1.3'
compile 'androidx.appcompat:appcompat:1.4.1'
compile 'androidx.recyclerview:recyclerview:1.2.1'
I don't know where to fix it.
I already have plugin kapt.
Maybe you could try to upgrade room annotation library from kapt to ksp.
kapt "androidx.room:room-compiler:2.4.2"
to
ksp "androidx.room:room-compiler:2.4.2"

Unresolved reference: bundleOf

After updating some dependencies(not sure which one, but it includes navigation-ktx and fragment-ktx), "bundleOf" disappeared. Was it deleted? Autocomplete suggests me only "persistableBundleOf()", but it's not what I need.
P.S. I have "implementation 'androidx.core:core-ktx:1.3.2'" too.
UPD: My build.gradle:
implementation 'androidx.fragment:fragment-ktx:1.3.1'
implementation 'androidx.preference:preference-ktx:1.1.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
def navigation_version = "2.3.4"
implementation "androidx.navigation:navigation-fragment-ktx:$navigation_version"
implementation "androidx.navigation:navigation-ui-ktx:$navigation_version"

unresolved reference :viewModels

I am new to android kotlin and I am using viewModel in my OCR App."import androidx.fragment.app.viewModels" is not showing.I have added all the neccessary dependencies.What am doing wrong ?
Here are the dependencies.
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.2'
implementation 'androidx.legacy:legacy-support-v4:1.0.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.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'com.google.android.material:material:1.2.1'
//lottie animation
implementation 'com.airbnb.android:lottie:3.4.1'
// Add CameraX dependencies
def camerax_version = "1.0.0-beta05"
implementation "androidx.camera:camera-core:${camerax_version}"
implementation "androidx.camera:camera-camera2:${camerax_version}"
implementation "androidx.camera:camera-lifecycle:${camerax_version}"
implementation "androidx.camera:camera-view:1.0.0-alpha12"
// Add ML Kit dependencies
implementation 'com.google.android.gms:play-services-mlkit-text-recognition:16.0.0'
implementation 'com.google.mlkit:language-id:16.0.0'
implementation 'com.google.mlkit:translate:16.0.0'
}
And these is the import error.
Add this dependency to use by viewModels() in a Fragment:
implementation 'androidx.fragment:fragment-ktx:1.2.5'

package android.support.design.widget does not exist after refactor dependencies - Androidx api 28

After refactoring dependencies to androidx dependencies with android studio I keep getting errors when building. I looks like the application still uses the old depedencies, but I have tried to clean projekt and rebuild project... nothing helped.
Below is the dependencies I use in my application.
def retrofit_version = "2.4.0"
def glide_version = "4.3.1"
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
// Design Support
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.vectordrawable:vectordrawable-animated:1.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"
implementation 'androidx.paging:paging-runtime:2.0.0'
implementation "com.github.bumptech.glide:glide:$glide_version"
annotationProcessor "com.github.bumptech.glide:compiler:$glide_version"
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel:2.0.0'
implementation 'androidx.preference:preference:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

GSON not deleted

Why in my APK there is GSON even though I have nothing to implement GSON in Gradle?
Result Analyze APK
My Gradle :
//main
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.anko:anko-commons:0.10.5"
implementation "androidx.appcompat:appcompat:1.1.0"
implementation "androidx.constraintlayout:constraintlayout:1.1.3"
implementation "androidx.recyclerview:recyclerview:1.1.0"
implementation "androidx.paging:paging-runtime:2.1.1"
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version"
implementation "androidx.room:room-runtime:$room_version"
implementation "androidx.multidex:multidex:2.0.1"
implementation "com.android.volley:volley:1.1.1"
//google
implementation "com.google.android.gms:play-services-location:17.0.0"
implementation "com.google.android.material:material:1.0.0"
implementation "com.google.firebase:firebase-auth:19.2.0"
implementation "com.google.firebase:firebase-firestore:21.3.1"
implementation "com.google.firebase:firebase-storage:19.1.0"
implementation "com.google.firebase:firebase-messaging:20.1.0"
implementation "com.firebaseui:firebase-ui-storage:3.3.0"
// third party dependencies
implementation "com.balysv:material-ripple:1.0.2"
implementation "com.facebook.shimmer:shimmer:0.5.0"
implementation "com.squareup.moshi:moshi-kotlin:1.9.2"
implementation "com.tbuonomo.andrui:viewpagerdotsindicator:4.1.2"
implementation "com.github.bumptech.glide:glide:$glide_version"
//noinspection GradleDependency
implementation "com.journeyapps:zxing-android-embedded:3.6.0"
//kapt
kapt "com.github.bumptech.glide:compiler:$glide_version"
kapt "androidx.room:room-compiler:$room_version"
kapt "androidx.annotation:annotation:1.1.0"
// test
testImplementation 'junit:junit:4.13'
androidTestImplementation "androidx.test:runner:1.2.0"
androidTestImplementation "androidx.test.espresso:espresso-core:3.2.0"
I want to reduce my apk size, so I deleted the libary that I didn't use.
One or more of your dependencies has GSON in self.
i think it might be Glide or someone else.
for redecuing apk size check this topic might be helpful: Reduce the APK size - Android Developers

Categories

Resources