ERROR: error.NonExistentClass Kotlin In a project with multiple Dagger modules

I use Dagger 2 and Kotlin for Android development. My project is also a multi-module project. My settings.gradle file looks like this:

include :app
include :lib

I also support the lib module.

In Dagger Files (for example, in a component) I am trying to get an item from another module. For example:

@Component
interface AppComponent{
    fun getPresenter() : Presenter
}

The Presenter object is defined in the lib module. I worked in a Linux environment and I use Android Studio 3 Preview Canary 5. The code works well and I can generate an APK.

But my company wanted to create an APK using a stable version of Android Studio. I am using Android Studio 2.3.3.

When compiling Android Project, I encountered this error:

error: error.NonExistentClass

The error appears when

:app:kaptDebugKotlin 

, , . ? .

+22
13

, , kapt. , , (OrmaDatabase):

Kotlin Java, Kotlin OrmaDatabase, . NonExistentClass. .

( )

plain apt annotationProcessor Dagger. :

kapt libs.daggerCompiler

to

annotationProcessor libs.daggerCompiler

build.gradle, . kapt, , Kotlin.

+20

NonExistentClass Dagger, , kotlin. , , :

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$rootProject.kotlinVersion"
+4

TL;DR: kapt annotationProcessor build.gradle, .

, , , AppComponent. , kapt . kapt annotationProcessor , , .

+3

gradle, , NonExistentClass

kapt {
 correctErrorTypes true 
} 

https://kotlinlang.org/docs/reference/kapt.html#non-existent-type-correction

+2

,

    kapt {
    generateStubs = true
}

false, , , , true,

+1

@Nullable support-annotations, , AndroidX.
, , .

.

+1

, . .

+1

, kapt, .

./gradlew clean
0

. Android Studio (3.4.c6), " ", . Parcelize.

0

.gradle .

mockito 2.7.21 2. + .

-    androidTestCompile "org.mockito:mockito-android:2.7.21" // remove this
+    androidTestCompile "org.mockito:mockito-android:2.+"    // add this
0

, , .

import foo.*  // class foo.Abc
import bar.*  // annotation bar.Abc

@Abc
class Xyz { ... }
0

, Injected. , , .

0

Android X , , .

:

, myModuleProject. Android X , android studio, CI , ':myModuleProject:kaptDebugKotlin'

e: /home/circleci/code/myModuleProject/build/tmp/kapt3/stubs/debug/package_name_here/reporter/bindingadapter/SomeBindingAdapterKt.java:14: error: incompatible types: NonExistentClass cannot be converted to Annotation
@error.NonExistentClass()

After two days of a nightmare, I found that not only the root project gradle.propertiesbut also the module projects should include the following!

android.databinding.enableV2=true
android.useAndroidX=true
android.enableJetifier=true
-1
source

All Articles