首先,

I'm pretty much aware that a lot of questions on this error had been posted already here, and none of them seems to be having a proper solution especially the one I need.

我被以下错误困扰了一个多星期.

我正在做一个android项目,它正在使用Kotlin、MVVM、Clean Arch和导航组件构建.

我最近添加了realm数据库,为此我必须添加以下插件.

apply plugin: 'kotlin-kapt'

apply plugin: 'realm-android'

我想真正的问题是从这里开始的.

(After that I added a DatabaseManager class which makes use of some realm extension functions I wrote to make db operations.)

当我在此之后编译项目时,总体上发生了以下错误.

A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution

以及以下内容

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:kaptDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution
   > java.lang.reflect.InvocationTargetException (no error message)

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.1.1/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 7s
30 actionable tasks: 6 executed, 24 up-to-date

它指向我的MainActivity类,该类没有改变,似乎没有任何错误或打字错误.I'm pretty much sure that the kapt annotation processor does some dirty job here that I do not seem to figure out.

enter image description here

I will be greatly relieved if I could get past this weird error.

其他注意事项:

  1. 我将整个项目分为三个模块.三个都有kapt插件(以防万一)

  2. I use Koin for DI

Hope someone will help me out!

推荐答案

经过一周的努力,我终于找到了问题所在.

我为王国添加了kotlin-kapt插件.

我有一个名为interface的文件夹,用来保存一些接口.

I implemented one of the interfaces from the interface folder in MainActivity.

现在界面的import是这样的,

import com.android.app.java.interface.Listener

Where, the keyword interface confused the annotation processor, hence caused error while generating stub.

I renamed the folder (from interface to intrface).

这就解决了这个错误.

This is a very simple mistake that cost me a week.

Anyway, found the issue. Yay!

Kotlin相关问答推荐

如果一项工作失败,请继续在Kotlin 等待其他工作/子元素完成

Kotlin协程挂起继续线程

Scala性状线性化等价于Kotlin

mutableStateOf 和 mutableStateListOf 有什么区别?

Kotlin:使用另一个列表和字母顺序对列表进行排序的有效方法

在 Kotlin 中 import 如何找到文件路径?

为什么 Kotlin 中的 Double 和 Long 类型不推荐直接转换为 Char?

kotlin 如何决定 lambda 中的参数名称?

Kotlin 使用迭代索引过滤 lambda 数组

IntentService (kotlin) 的默认构造函数

如何在 Kotlin 文件中的 Android Studio 中控制何时将 Imports 替换为通配符

Kotlin 类的调用方法

Kotlin 中的内联构造函数是什么?

如何使用协调器布局和行为在CardView上完成此动画?

如何在Kotlin中使方法param可变?

如何使用mockk库模拟android上下文

在 Kotlin 中声明 Byte 会出现编译时错误The integer literal does not conform to the expected type Byte

函数引用和lambdas

如何在 Kotlin 中将串联转换为模板

如何在 Kotlin 中生成 MD5 哈希?