【问题标题】:Databinding annotation processor kapt warning数据绑定注释处理器 kapt 警告
【发布时间】:2018-10-12 17:39:44
【问题描述】:

在我的应用模块的 build.gradle 中,我添加了

dependencies {
kapt('com.android.databinding:compiler:3.1.2')
...
}

但我仍然收到

的编译器警告
app: 'annotationProcessor' dependencies won't be recognized as kapt annotation processors. Please change the configuration name to 'kapt' for these artifacts: 'com.android.databinding:compiler:3.1.2'.

一切正常,我只是讨厌到处出现警告。

非常感谢任何帮助!

【问题讨论】:

  • 你还有其他使用annotationProcessor的依赖吗?
  • 在我的 build.gradle 中,所有其他依赖项都是“implementation”、“testImplementation”或“androidTestImplementation”。我不知道我拥有的第 3 方依赖项是否正在使用注释处理。
  • 这里有同样的问题。另外我得到这个错误: e: java.util.ServiceConfigurationError: javax.annotation.processing.Processor: android.databinding.annotationprocessor.ProcessDataBinding Unable to get public no-arg constructor
  • kapt 用于 kotlin,annotationProcessor 用于 java 代码
  • @RyanAmaral,我知道这一点,并在我的 build.gradle(上图)中使用 kapt,但仍然收到警告

标签: android kotlin annotation-processing kapt


【解决方案1】:

在升级到最新的 Android Gradle 构建插件和 Kotlin 之前,我收到了同样的警告。现在他们走了。这是我使用的配置。

project.gradle

buildscript {
    dependencies {
        classpath "com.android.tools.build:gradle:3.1.3"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.51"
    }
}

module.gradle

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

android {
    ...
    dataBinding {
        enabled = true
    }
}

dependencies {
    // no kapt declaration for databinding here
}

希望对你有帮助。

【讨论】:

  • 看起来更新到 1.2.51 并删除 kapt 依赖修复它
【解决方案2】:

在你里面添加关注app build.gradle

kapt "com.android.databinding:compiler:$android_plugin_version"
apply plugin: 'kotlin-kapt' // This one at top where plugin belong to

这样就可以了。

$android_plugin_versioncom.android.tools.build:gradleapplication build.gradle 中的版本

另外,将此添加到您的模块build.gradle

android {
    /// Existing Code
    kapt {
        generateStubs = true
    }
}

我想你错过了apply plugin: 'kotlin-kapt'

【讨论】:

  • 现在:“kotlin-kapt”插件不使用“kapt.generateStubs”
猜你喜欢
  • 2011-01-06
  • 2017-10-26
  • 1970-01-01
  • 2017-10-22
  • 2018-01-17
  • 1970-01-01
  • 2018-06-29
  • 1970-01-01
  • 2017-03-21
相关资源
最近更新 更多