Kotlin: How to Solve kapt import error

The first problem encountered was that the BR file could not be found

Log: unresolved reference: BR

Reason: the plug-in developed by kotlin does not support cross module, so the reference of databinding when using APT Technology br file does not determine the directory, so the error (unresolved reference: be) is caused, so it needs to be completed by kapt

Solution:

apply plugin: 'kotlin-kapt'
kapt {
    generateStubs = true
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    //The version should be the same as the gradle version
    kapt  "com.android.databinding:compiler:3.5.0"
}

New problem: Class not found Custom generated class can not be generated.

Reason: If you already have kapt, you need to replace it with kapt

Solution: In Kotlin, you need to add the kotlin-kapt plugin to activate kapt and replace the annotationProcessor with kapt.

Read More: