在Android Studio中Kotlin构建失败

错误:

Error:Execution failed for task ':synclib:compileKotlin'. > com.intellij.openapi.fileTypes.LanguageFileType.(Lcom/intellij/lang/Language;)V 

synclib模块的build.gradle文件:

 apply plugin: 'java' apply plugin: 'kotlin' compileJava { sourceCompatibility = 1.7 targetCompatibility = 1.7 } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' // compile 'com.android.support:appcompat-v7:23.1.1' compile 'com.firebase:firebase-client-jvm:2.2.3' compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" compile project(':jamodel') } buildscript { ext.kotlin_version = '1.0.0' repositories { mavenCentral() } dependencies { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } repositories { mavenCentral() } 

如何解决或诊断这个?

这是一个工作配置。 您可以将其调整为您的多项目设置:

/build.gradle

 buildscript { ext.kotlin_version = '1.0.4' repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:2.2.0' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } allprojects { repositories { jcenter() } ext { androidBuildToolsVersion = "23.0.3" androidMinSdkVersion = 16 androidTargetSdkVersion = 23 androidCompileSdkVersion = 23 androidApplicationId = "com.some.example" androidVersionCode = 1 androidVersionName = "1.0" supportVersion = "24.0.0" } } 

/app/build.gradle

 apply plugin: 'com.android.application' apply plugin: 'kotlin-android' android { compileSdkVersion parent.ext.androidCompileSdkVersion buildToolsVersion parent.ext.androidBuildToolsVersion defaultConfig { minSdkVersion parent.ext.androidMinSdkVersion targetSdkVersion parent.ext.androidTargetSdkVersion versionCode parent.ext.androidVersionCode versionName parent.ext.androidVersionName } buildTypes { debug { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } packagingOptions { exclude 'LICENSE.txt' exclude 'META-INF/LICENSE.txt' exclude 'META-INF/NOTICE.txt' exclude 'META-INF/LICENSE' exclude 'META-INF/NOTICE' } dexOptions { preDexLibraries = false jumboMode = false javaMaxHeapSize "4g" } } dependencies { compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" } 

按照这些说明或检查: https : //kotlinlang.org/docs/tutorials/kotlin-android.html

  1. 选择帮助| 在主菜单上查找操作或按CTRL + Shift + A。
  2. 搜索这个项目: 在这里输入图像说明
  3. 您将被提示输入kotlin版本。

*强调文字* 从已安装的版本列表中选择最新版本。

  1. 现在应该更新应用程序的build.gradle文件。

  2. 最后要做的是sync the project 。 您可以在提示中按“ Sync Now ”,或使用Gradle文件调用同步项目

希望它会有所帮助

确保所有的应用程序和库build.gradleext.kotlin_version等于您安装的Kotlin版本

 buildscript { ext.kotlin_version = PROP_KOTLIN_VERSION // 1.1.2-3 // this should equal to your installed Kotlin version //... }