建立火箭聊天机器人代码时,出现此错误。
无法获取类型为org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler的对象的未知属性“库”。
core / build.gradle
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 28
defaultConfig {
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/core.kotlin_module'
exclude 'META-INF/main.kotlin_module'
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation libraries.kotlin
implementation libraries.coroutines
implementation libraries.lifecycleExtensions
kapt libraries.lifecycleCompiler
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.2.71"}
repositories {
mavenCentral()
}
答案 0 :(得分:0)
尝试添加以下行:
kapt "androidx.lifecycle:lifecycle-compiler:2.0.0"
答案 1 :(得分:0)
core/build.gradle
不会检测到您正在使用的扩展名。有几种解决方法。
您可以从定义它们的dependencies.gradle
解析依赖项。在查看Rocket.Chat.Android示例时,扩展看起来像这样:
ext {
versions = [
kotlin : '1.2.61',
coroutine : '0.25.0',
...
lifecycle : '2.0.0',
...
]
libraries = [
kotlin : "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${versions.kotlin}",
coroutines : "org.jetbrains.kotlinx:kotlinx-coroutines-core:${versions.coroutine}",
...
lifecycleExtensions : "androidx.lifecycle:lifecycle-extensions:${versions.lifecycle}",
lifecycleCompiler : "androidx.lifecycle:lifecycle-compiler:${versions.lifecycle}",
...
]
}
和您的core/build.gradle
的依存关系块如下所示:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.2.61"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:0.25.0"
implementation "androidx.lifecycle:lifecycle-extensions:2.0.0"
kapt "androidx.lifecycle:lifecycle-compiler:2.0.0"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.2.71"
}
或者,您可以将dependencies.gradle
文件应用于core/build.gradle
,我认为它应该检测在那里定义的额外属性。
我正在谈论将apply from: "../dependencies.gradle"
添加到您的core/build.gradle
中。