错误:(1,0)找不到ID为'kotlin-android-extensions'的插件

Isl*_*baz 31 android-studio kotlin-android-extensions android-studio-3.0

apply plugin: 'kotlin-android-extensions'.
Run Code Online (Sandbox Code Playgroud)

当我在android studio预览中添加此扩展时,请给我这个错误"错误:(1,0)插件ID为'kotlin-android-extensions'找不到."

我的构建gradle

   apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"
    defaultConfig {
        applicationId "com.example.mohamed_elbaz.myapplication"
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.0.2'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
Run Code Online (Sandbox Code Playgroud)

use*_*913 47

您发布的build.gradle代码段看起来像应用程序模块中的配置.项目根目录中的build.gradle是什么样的?要添加kotlin插件依赖项,它应该看起来像这样:

buildscript {
    ext.kotlin_version = '1.1.50'
    repositories {
        jcenter()
        google()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0-beta6'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        google()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
Run Code Online (Sandbox Code Playgroud)

重要的部分是classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"添加kotlin插件的线.

  • 您可以在此处找到最新的 kotlin 插件版本:https://plugins.jetbrains.com/plugin/6954-kotlin (6认同)

Md *_*ury 29

要使用该插件,您必须将其添加到根build.gradle文件中

buildscript {
ext.kotlin_version = '1.1.60'
    repositories {
        jcenter()
        maven {
            url 'https://maven.google.com'
        }
    }

    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}
Run Code Online (Sandbox Code Playgroud)