Kotlin构建在Android Studio中失败

时间:2016-10-23 19:40:51

标签: android android-studio gradle android-gradle kotlin

错误:

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

build.gradle模块的synclib文件:

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()
}

如何修复或诊断?

3 个答案:

答案 0 :(得分:1)

这是一个有效的配置。您可以根据多项目设置进行调整:

/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"
}

答案 1 :(得分:1)

请按照以下说明操作或查看:https://kotlinlang.org/docs/tutorials/kotlin-android.html

  1. 选择帮助|在主菜单上找到行动或按 CTRL + Shift + A
  2. 搜索此项目:enter image description here
  3. 系统会提示您输入build.gradle版本。
  4. *emphasized text*   从已安装的版本列表中选择最新的。

    1. 现在应该更新应用程序的sync the project文件。

    2. 最后要做的是Sync Now。您可以在提示中按“ if ('serviceWorker' in navigator) { console.log('Service Worker is supported'); navigator.serviceWorker.register('sw.js').then(function() { return navigator.serviceWorker.ready; }).then(function(reg) { console.log('Service Worker is ready :^)', reg); reg.pushManager.subscribe({userVisibleOnly: true}).then(function(sub) { // not reached here console.log('endpoint:', sub.endpoint); }); }).catch(function(error) { console.log('Service Worker error :^(', error); }); } ”或调用使用Gradle文件同步项目操作。

    3. 希望它会有所帮助

答案 2 :(得分:0)

确保您的所有应用和库build.gradle ext.kotlin_version等于您安装的Kotlin版

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