app模块中引用的android库模块的"未解析的引用"错误

Lem*_*981 25 android android-library kotlin android-studio android-gradle-plugin

我在项目中引用我的android库模块时遇到问题.在主应用程序模块旁边,我使用了一个带有util东西或数据模块的android库模块.我在app模块中引用它是这样的:

dependencies {
    implementation project(":data")
}
Run Code Online (Sandbox Code Playgroud)

当我构建项目时,它为我'Unresolved reference: ...'在app模块中引用到android库模块的所有内容提供了很多错误消息.但IDE本身没有问题,Intelligent发现所有类,接口等,导入很好,没有什么是红色的.android库模块本身aar-file在输出中构建和创建.这compileDebugKotlin是失败的任务

可能与此相关的一般概念是什么?

Lem*_*981 86

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

apply plugin: 'kotlin-android'

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlinVersion:<version>"
}
Run Code Online (Sandbox Code Playgroud)

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

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

曾告诉我'所有带Kotlin文件的模块都已配置'

  • 我有相同的问题,除了..我的项目没有缺少任何依赖关系..我希望此错误更具描述性。 (2认同)
  • 一年半过去了,他们还没有解决这个问题。谷歌请抛出一个真正的错误。当 IDE 告诉您一切都很好时,这并不酷。 (2认同)

Ank*_*mar 18

您的模块的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"
    ...
}
Run Code Online (Sandbox Code Playgroud)


Dou*_*ita 14

在我的情况下它是apply plugin: 'kotlin-android',

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
Run Code Online (Sandbox Code Playgroud)

并在build.gradle上添加了它

androidExtensions {
  experimental = true
}
Run Code Online (Sandbox Code Playgroud)


Eme*_*kpo 6

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

apply plugin: 'kotlin'

  • 如果它是一个通用库,这个很有用! (2认同)