【问题标题】:Gradle DSL method not found: 'kapt()' and Plugin with id 'kotlin-kapt' not found未找到 Gradle DSL 方法:未找到“kapt()”和 ID 为“kotlin-kapt”的插件
【发布时间】:2019-08-21 19:54:21
【问题描述】:

我使用 Algolia 开发了一个带有搜索界面的 Android 应用。

为此,我遵循InstantSearch 的本指南,但是当我将kapt "androidx.lifecycle:lifecycle-compiler:2.0.0" 依赖项添加到我的应用程序 build.gradle 时,我收到了ERROR: Gradle DSL method not found: 'kapt()' 错误。

我尝试在 app build.gradle 文件的顶部添加apply plugin: 'kotlin-kapt'(请参阅this),但随后出现Plugin with id 'kotlin-kapt' not found. 错误。

这是我的应用 build.gradle 文件:

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'kotlin-kapt'

android {
    buildToolsVersion "28.0.3"
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.memoryDiary.Activity.Start"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    //noinspection GradleCompatible
    implementation 'androidx.appcompat:appcompat:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    implementation 'com.sangcomz:FishBun:0.9.1'
    implementation 'com.squareup.picasso:picasso:2.71828'
    implementation 'com.getbase:floatingactionbutton:1.10.1'
    implementation 'com.github.clans:fab:1.6.4'
    implementation 'com.github.bumptech.glide:glide:4.9.0'
    implementation 'com.mobsandgeeks:android-saripaar:2.0.3'
    implementation 'androidx.legacy:legacy-support-v13:1.0.0'

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'

    implementation 'com.google.firebase:firebase-auth:17.0.0'
    implementation 'com.google.firebase:firebase-database:17.0.0'
    implementation 'com.google.firebase:firebase-core:16.0.9'
    implementation 'com.google.firebase:firebase-storage:17.0.0'
    implementation 'com.google.firebase:firebase-ml-vision:22.0.0'
    implementation 'com.google.firebase:firebase-ml-vision-image-label-model:18.0.0'

    implementation 'com.algolia:algoliasearch-android:3.+'
    implementation 'com.algolia:instantsearch-android:2.0.0'
    implementation "androidx.lifecycle:lifecycle-extensions:2.0.0"
    kapt "androidx.lifecycle:lifecycle-compiler:2.0.0"

    implementation 'com.google.code.gson:gson:2.8.5'
}

我该如何解决这个问题?

【问题讨论】:

  • 请粘贴您的 build.gradle 文件。
  • @barq 我贴了。

标签: android-studio kotlin build.gradle algolia kapt


【解决方案1】:

您还需要应用以下插件:

apply plugin: 'kotlin-android'

【讨论】:

  • 我添加了classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.41",但它仍然无法处理Gradle DSL method not found: 'kapt()' 错误。
【解决方案2】:

如果你使用 kotlin,你必须使用这个:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

【讨论】:

  • 您好,apply plugin: 'kotlin-android-extensions' 是可选的,如果您使用 android 的 kotlin 扩展,请添加此行。
猜你喜欢
  • 2019-09-29
  • 1970-01-01
  • 1970-01-01
  • 2019-03-05
  • 2015-09-25
  • 2015-05-19
  • 2017-04-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多