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

apply plugin: 'kotlin-android-extensions'. 

当我在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' } 

你发布的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 } 

其中最重要的部分就是添加kotlin插件的行classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"