应用程序模块中引用的 android 库模块的 'Unresolved reference' 个错误

'Unresolved reference' errors for android library module referenced in app module

我在项目中引用 android 库模块时遇到问题。除了主应用程序模块之外,我还使用了一个 android 库模块,其中包含 util 内容或作为数据模块。我在应用程序模块中这样引用它:

dependencies {
    implementation project(":data")
}

当我构建项目时,它为我在应用程序模块中引用到 android 库模块的所有内容提供了很多错误消息 'Unresolved reference: ...'。但是 IDE 本身没有问题,智能找到所有 类,接口等,导入都很好,没有什么是红色的。 android 库模块本身在输出中构建并创建 aar-filecompileDebugKotlin 任务失败了

任何可能与此相关的一般想法?

发现问题,我的 android 库模块缺少 kotlin 配置:

apply plugin: 'kotlin-android'

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlinVersion:<version>"
}

虽然我在其中使用了 kotlin .kt 文件,但它可以在没有和的情况下构建

Tools -> Kotlin -> 'Configure Kotlin in projects'

告诉过我'All modules with Kotlin files are configured'

您模块的 build.gradle 文件应包含:

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

dependencies {
    ...
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    ...
}

在我的例子中是 apply plugin: 'kotlin-android',

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

并且还在 build.gradle

上添加了它
androidExtensions {
  experimental = true
}

如果它是 kotlin 模块,请确保在其 build.gradle 文件中添加

apply plugin: 'kotlin'

我正在使用 CoroutineWorkers,在我的例子中,我必须添加 work-runtime-ktx 依赖项才能使用它

implementation "androidx.work:work-runtime-ktx:2.4.0"