Unable to instantiate application on path: DexPathList - kotlin

I saw this problem and I don't know what caused it or how to solve it
Simply the application crashed with no reason and nothing weird!
this is the problem from logcat:
2021-12-01 00:08:56.105 27747-27747/com.example.halanchallenge E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.halanchallenge, PID: 27747
java.lang.RuntimeException: Unable to instantiate application com.example.halanchallenge.presentation.utils.manager.BaseApplication: java.lang.ClassNotFoundException: Didn't find class "com.example.halanchallenge.presentation.utils.manager.BaseApplication" on path: DexPathList[[zip file "/data/app/~~AByZTfuIHlZhPYmwpjE5lQ==/com.example.halanchallenge-B7fNXgixWuCCl0Iug8pygQ==/base.apk"],nativeLibraryDirectories=[/data/app/~~AByZTfuIHlZhPYmwpjE5lQ==/com.example.halanchallenge-B7fNXgixWuCCl0Iug8pygQ==/lib/arm64, /system/lib64, /system/system_ext/lib64]]
at android.app.LoadedApk.makeApplication(LoadedApk.java:1332)
at android.app.ActivityThread.handleMakeApplication(ActivityThread.java:7469)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7440)
at android.app.ActivityThread.access$1400(ActivityThread.java:301)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2148)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:246)
at android.app.ActivityThread.main(ActivityThread.java:8506)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.halanchallenge.presentation.utils.manager.BaseApplication" on path: DexPathList[[zip file "/data/app/~~AByZTfuIHlZhPYmwpjE5lQ==/com.example.halanchallenge-B7fNXgixWuCCl0Iug8pygQ==/base.apk"],nativeLibraryDirectories=[/data/app/~~AByZTfuIHlZhPYmwpjE5lQ==/com.example.halanchallenge-B7fNXgixWuCCl0Iug8pygQ==/lib/arm64, /system/lib64, /system/system_ext/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:207)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.app.AppComponentFactory.instantiateApplication(AppComponentFactory.java:76)
at androidx.core.app.CoreComponentFactory.instantiateApplication(CoreComponentFactory.java:52)
at android.app.Instrumentation.newApplication(Instrumentation.java:1158)
at android.app.LoadedApk.makeApplication(LoadedApk.java:1324)
at android.app.ActivityThread.handleMakeApplication(ActivityThread.java:7469) 
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7440) 
at android.app.ActivityThread.access$1400(ActivityThread.java:301) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2148) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loop(Looper.java:246) 
at android.app.ActivityThread.main(ActivityThread.java:8506) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130) 
Suppressed: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/example/halanchallenge/presentation/utils/manager/Hilt_BaseApplication;
at java.lang.VMClassLoader.findLoadedClass(Native Method)
at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:738)
at java.lang.ClassLoader.loadClass(ClassLoader.java:363)
... 15 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.halanchallenge.presentation.utils.manager.Hilt_BaseApplication" on path: DexPathList[[zip file "/data/app/~~AByZTfuIHlZhPYmwpjE5lQ==/com.example.halanchallenge-B7fNXgixWuCCl0Iug8pygQ==/base.apk"],nativeLibraryDirectories=[/data/app/~~AByZTfuIHlZhPYmwpjE5lQ==/com.example.halanchallenge-B7fNXgixWuCCl0Iug8pygQ==/lib/arm64, /system/lib64, /system/system_ext/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:207)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
... 18 more
And this is my gradle file :
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
id 'androidx.navigation.safeargs.kotlin'
id 'dagger.hilt.android.plugin'
id 'kotlin-parcelize'
}
android {
compileSdkVersion 31
defaultConfig {
applicationId "com.example.halanchallenge"
minSdkVersion 21
targetSdkVersion 31
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
buildConfigField("String", "BASE_URL", BASE_URL)
}
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'
}
dataBinding {
enabled = true
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
testImplementation 'junit:junit:'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation 'com.android.support:multidex:1.0.3'
//Dagger - Hilt
implementation "com.google.dagger:hilt-android:2.38.1"
annotationProcessor "com.google.dagger:hilt-android-compiler:2.38.1"
annotationProcessor 'androidx.hilt:hilt-compiler:1.0.0'
implementation 'androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha03'
//GIF
implementation "com.airbnb.android:lottie:3.7.0"
// Glide
implementation 'com.github.bumptech.glide:glide:4.12.0'
kapt 'com.github.bumptech.glide:compiler:4.12.0'
// Retrofit
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation "com.squareup.okhttp3:logging-interceptor:5.0.0-alpha.2"
// Coroutines
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.1'
// Coroutine Lifecycle Scopes
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.4.0"
//GSON
implementation 'com.google.code.gson:gson:2.8.7'
// Navigation Components
implementation "androidx.navigation:navigation-fragment-ktx:2.3.5"
implementation "androidx.navigation:navigation-ui-ktx:2.3.5"
implementation 'de.hdodenhof:circleimageview:3.1.0'
implementation 'com.github.martinstamenkovski:ARIndicatorView:2.0.0'
implementation 'com.amitshekhar.android:android-networking:1.0.2'
}
Gradle :
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.5.31"
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.3.5"
classpath 'com.google.dagger:hilt-android-gradle-plugin:2.38.1'
}
}
allprojects {
repositories {
google()
maven { url 'https://jitpack.io' }
mavenCentral()
jcenter() // Warning: this repository is going to shut down soon
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
And this is the BaseApplication
#HiltAndroidApp
class BaseApplication : Application()
What is the problem and how to solve it ?
I've been thinking about a solution for a long time and haven't found a solution!
I hope you can help me solve it.
Thank you :))

Try to update you Hilt dependencies to v2.40.2
// :app build.gradle START
plugins {
id 'kotlin-android'
id 'kotlin-kapt'
//...
id 'dagger.hilt.android.plugin'
}
android {
//...
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
//...
}
dependencies {
//...
// hilt
implementation "com.google.dagger:hilt-android:2.40.2"
kapt "com.google.dagger:hilt-compiler:2.40.2"
}
// Allow references to generated code
kapt {
correctErrorTypes = true
}
// :app build.gradle END
// project build.gradle START
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.5.31"
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.3"
//...
classpath 'com.google.dagger:hilt-android-gradle-plugin:2.40.2'
}
}
// ...
// project build.gradle END

Related

How can I add serialization dependencies to my kotlin project?

I am trying to add json serialization dependencies in my kotlin project but it doesnt work and lots of error appear when I sync project. I dont know why. I did as in the serialization dependency addition section on the kotlin web site, but it didn't work. how do I add it to my codes ?.
Build.Gragle(project)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
compose_version = '1.0.1'
}
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.2.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.21"
classpath 'com.google.dagger:hilt-android-gradle-plugin:2.44'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Build.Gradle(module)
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
id 'org.jetbrains.kotlin.android.extensions'
}
android {
compileSdk 32
defaultConfig {
applicationId "com.enestigli.dictionaryapp"
minSdk 21
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 {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion compose_version
}
packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
androidExtensions {
experimental = true
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
implementation 'androidx.activity:activity-compose:1.3.1'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version"
// Retrofit
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation "com.squareup.okhttp3:okhttp:4.9.0"
implementation "com.squareup.okhttp3:logging-interceptor:4.9.0"
//Dagger - Hilt
implementation "com.google.dagger:hilt-android:2.38.1"
kapt "com.google.dagger:hilt-android-compiler:2.38.1"
//implementation "androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha03"
kapt "androidx.hilt:hilt-compiler:1.0.0"
implementation 'androidx.hilt:hilt-navigation-compose:1.0.0-alpha03'
// Coroutines
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.1'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.1'
// Coroutine Lifecycle Scopes
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.3.1"
// Room
implementation "androidx.room:room-runtime:2.3.0"
kapt "androidx.room:room-compiler:2.3.0"
// To use Kotlin annotation processing tool (kapt)
// Kotlin Extensions and Coroutines support for Room
implementation "androidx.room:room-ktx:2.3.0"
//Material theme3
implementation "androidx.compose.material3:material3:1.0.0-alpha12"
implementation "androidx.compose.material3:material3-window-size-class:1.0.0-alpha12"
//skrape{it}
//implementation 'org.jsoup:jsoup:1.12.1'
//compose
implementation "androidx.compose.runtime:runtime-livedata:$compose_version"
}
EDIT
I found the solution
In this case, you need to install whatever Kotlin version is. In my case like this
my kotlin version is : 1.5.21
and I added this dependency in gradle.plugin(module)
plugins {
id 'org.jetbrains.kotlin.plugin.serialization' version '1.5.21'
}
and I added this
dependencies {
implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1'
}
and that's it, now you can use serialization in your data class like this.
for example
import kotlinx.serialization.Serializable
#Serializable
data class example(
val example: String,
)

Error resolving jetpack compose dependencies in version 1.1.0-rc02

Problem description
I'm trying to use the latest version of jetpack compose 1.1.0-rc02, but some dependencies are returning an error:
Failed to resolve: androidx.compose.material:material:1.1.0-rc02
Failed to resolve: androidx.compose.ui:ui:1.1.0-rc02
Failed to resolve: androidx.compose.ui:ui-tooling:1.1.0-rc02
Failed to resolve: androidx.compose.ui:ui-tooling-preview:1.1.0-rc02
Failed to resolve: androidx.compose.ui:ui-test-junit4:1.1.0-rc02
My gradle files
Project scope
buildscript {
ext {
compose_version = '1.1.0-rc02'
kotlin_version = '1.6.10'
hilt_version = '2.38.1'
}
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.4"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "com.google.dagger:hilt-android-gradle-plugin:$hilt_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Application scope
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
}
android {
compileSdk 31
defaultConfig {
applicationId "com.plcoding.dictionary"
minSdk 21
targetSdk 31
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'
useIR = true
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion compose_version
kotlinCompilerVersion kotlin_version
}
packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'com.google.android.material:material:1.4.0'
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.0'
implementation 'androidx.activity:activity-compose:1.4.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
// Compose dependencies
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:2.4.0"
// Coroutines
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2'
// Coroutine Lifecycle Scopes
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0"
//Dagger - Hilt
implementation "com.google.dagger:hilt-android:$hilt_version"
kapt "com.google.dagger:hilt-android-compiler:$hilt_version"
implementation "androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha03"
kapt "androidx.hilt:hilt-compiler:1.0.0"
implementation 'androidx.hilt:hilt-navigation-compose:1.0.0-rc01'
// Retrofit
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation "com.squareup.okhttp3:okhttp:5.0.0-alpha.2"
implementation "com.squareup.okhttp3:logging-interceptor:5.0.0-alpha.2"
// Room
implementation "androidx.room:room-runtime:2.4.0"
kapt "androidx.room:room-compiler:2.4.0"
// Kotlin Extensions and Coroutines support for Room
implementation "androidx.room:room-ktx:2.4.0"
}
Here is a code version of the same answer #Francesc gave:
// Inside project's build.gradle file
buildscript {
ext {
// Define the 2 versions
compose_compiler_version = '1.1.0-rc02'
compose_version = '1.1.0-rc01'
}
...
}
Then inside your android module (app/library):
// Inside module's build.gradle file
android {
...
composeOptions {
// Compose compiler uses 'compose_compiler_version'
kotlinCompilerExtensionVersion compose_compiler_version
}
}
dependencies {
...
// Compose dependencies use 'compose_version'
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
}
RC02 is only available for the compose compiler to make it compatible with Kotlin 1.6.10. All other libraries are still in RC01, so for now you have to specify different versions for the compiler and the other compose dependencies.

Unable to resolve dependency for ':app#debugUnitTest/compileClasspath': Could not resolve androidx.constraintlayout:constraintLayout:1.1.3

y build is failing with the error message
Unable to resolve dependency for ':app#debugUnitTest/compileClasspath': Could not resolve androidx.constraintlayout:constraintLayout:1.1.3
ConstraintLayout version:1.1.3
Gradle plugin version : 4.0.1
Gradle version : 6.1.1
My app_build gradle is as follows
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.xxxxx.xxxxxxx"
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintLayout:1.1.3'
implementation 'androidx.annotation:annotation:1.1.0'
// To use the Java-compatible #Experimental API annotation
implementation "androidx.annotation:annotation-experimental:1.0.0"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
def room_version = "2.2.5"
def lifecycle_version = "2.2.0"
implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"
// For Lifecycle dependencies:
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
annotationProcessor "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"
// optional - RxJava support for Room
implementation "androidx.room:room-rxjava2:$room_version"
// Test helpers
testImplementation "androidx.room:room-testing:$room_version"
}
My project build.gradle is
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven {
// For Room Persistence Library
url "https://maven.google.com"
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
The package androidx.constraintlayout does not exist in jcenter()
https://jcenter.bintray.com/androidx/
what you can do however,
allprojects {
repositories {
mavenCentral()
google()
jcenter()
maven {
// For Room Persistence Library
url "https://maven.google.com"
}
} }

Android Kotlin Two-Way databinding BR class error

I'am trying to do a basic android application using kotlin and two way data binding to show on a text view the changes in a edit text. But i'am getting this error :
w: [kapt] Incremental annotation processing requested, but support is disabled because the following processors are not incremental: android.databinding.annotationprocessor.ProcessDataBinding (DYNAMIC).
when i'am trying to do with one way data binding it is working well it show me the Contact class's name field successful
my codes:
build.gradle(Project)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.3.61'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle(module:app)
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
dataBinding{
enabled = true
}
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.mvvm.demo"
minSdkVersion 16
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'
}
}
}
dependencies {
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.1.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'
}
my Contact.kt
import androidx.databinding.BaseObservable
import androidx.databinding.Bindable
class Contact( var Id:Int,
var Name:String,
var Email:String):BaseObservable() {
#Bindable
var _name: String = Name
set(value) {
field = value
notifyPropertyChanged(BR._name)
}
get() = field
}
unfortunately, this error has not yet been resolved. I hope the warning will be resolved in the next update. I've been waiting for updates since November because of this warning
source: https://issuetracker.google.com/issues/110061530#comment28

NonExistentClass cannot be converted to Annotation - app:kaptDebugAndroidTestKotlin

I want to test a class using JUnit5 but at the time gradle runs the app:kaptDebugAndroidTestKotlin task I get the issue.
I have already tried the solutions in the following links but nothing helps so far:
NonExistentClass cannot be converted to Annotation
error: incompatible types: NonExistentClass cannot be converted to Annotation #error.NonExistentClass()
my project build.gradle file:
buildscript {
ext.kotlin_version = '1.3.40'
ext.anko_version='0.10.8'
ext.junit_version='5.5.0'
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "io.realm:realm-gradle-plugin:5.11.0"
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
my module build.gradle file:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'realm-android'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.hays.test"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
androidExtensions {
experimental = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
}
realm {
kotlinExtensionsEnabled = true
}
kapt {
correctErrorTypes = true
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.core:core-ktx:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.0.0'
testImplementation "org.junit.jupiter:junit-jupiter-api:$junit_version"
testImplementation "org.junit.jupiter:junit-jupiter-engine:$junit_version"
testImplementation "org.junit.vintage:junit-vintage-engine:$junit_version"
testImplementation 'io.mockk:mockk:1.9.3'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
implementation 'io.reactivex.rxjava2:rxjava:2.2.9'
implementation 'io.reactivex.rxjava2:rxkotlin:2.3.0'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.github.bumptech.glide:glide:4.9.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
implementation 'com.squareup.okhttp3:okhttp:3.12.0'
implementation 'com.jakewharton.rxbinding2:rxbinding:2.2.0'
implementation 'com.jakewharton.rxbinding2:rxbinding-appcompat-v7:2.2.0'
implementation 'com.android.support:support-annotations:28.0.0'
implementation group: 'org.jetbrains.kotlinx', name: 'kotlinx-coroutines-android', version: '1.3.0-M1'
implementation "org.jetbrains.anko:anko:$anko_version"
}
and my gradle.properties file:
kotlin.code.style=official
org.gradle.jvmargs=-Xmx1536m
android.useAndroidX=true
android.enableJetifier=true
android.databinding.enableV2=true
I tried to run the test but what I get while compiling is the following:
C:\project_path\app\build\tmp\kapt3\stubs\debugAndroidTest\com\package\test\module\search\SearchPresenterTest.java:20: error: incompatible types: NonExistentClass cannot be converted to Annotation
#error.NonExistentClass()
The file under build folder has some of the following:
#error.NonExistentClass()
public final void setUpMocks() {
}
#error.NonExistentClass()
public final void onSearch() {
}
While the original kotlin test file is like the following lines:
#BeforeEach
fun setUpMocks() {
clearAllMocks()
}
#Test
fun onSearch() {
verify { view.onSearch() }
}
Seems that I mixed some JUnit4 dependencies with those of JUnit5 so by removing the following lines (like the AndroidJUnitRunner class) in the dependencies I got it working:
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
kapt("org.jetbrains.kotlin.kapt:org.jetbrains.kotlin.kapt.gradle.plugin:1.3.31:pom")
And I added back again those of the jupiter packages:
testImplementation "org.junit.jupiter:junit-jupiter-api:$junit_version"
testImplementation "org.junit.jupiter:junit-jupiter-engine:$junit_version"
testImplementation "org.junit.vintage:junit-vintage-engine:$junit_version"
Also the org.junit classes in all the tests have to be replaced by their equivalent of the org.junit.jupiter package.
That made it compile the test without issues.