Gradle 3.0.0-alpha1与kotlin-android插件1.1.2-3不兼容?

4
我安装了Android Studio 3.0 Canary 1并使用Kotlin创建了新项目。但是出现了以下错误:

Error:Unable to find method 'com.android.build.gradle.internal.variant.BaseVariantData.getOutputs()Ljava/util/List;'。 可能导致此意外错误的原因包括:

  • Gradle的依赖缓存可能已损坏(有时在网络连接超时后会发生)。重新下载依赖项并同步项目(需要网络)
  • Gradle构建进程(守护程序)的状态可能已损坏。停止所有Gradle守护程序可能会解决此问题。停止Gradle构建过程(需要重新启动)
  • 您的项目可能正在使用与项目中的其他插件或项目请求的Gradle版本不兼容的第三方插件。
如果Gradle进程损坏,您还可以尝试关闭IDE,然后杀死所有Java进程。

如果我从build.gradle中删除kotlin-android插件,则可以成功构建。

Build gradle:

buildscript {
    ext.kotlin_version = '1.1.2-3'
    repositories {
        maven { url 'https://maven.google.com' }
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0-alpha1'
        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()
        maven { url 'https://maven.google.com' }
        mavenCentral()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

app\build.gradle

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

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

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
    compile 'com.android.support:appcompat-v7:25.3.1'
    testCompile 'junit:junit:4.12'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.android.support:design:25.3.1'
}

有人知道如何解决这个问题吗?


你可以通过链接到重复的问题和答案来改进你的“重复”回答。并不是我们所有人都发现了这一点。 - ErstwhileIII
2个回答

14
您需要将Kotlin插件版本更改为 1.1.2-4

2
我使用了这个Kotlin版本,但仍然遇到了相同的问题。 - Mahesh Kavathiya

1
当您从旧版本的Android Studio导入设置时,会发生这种情况。将您的Kotlin插件版本升级至1.1.2-4,并删除文件夹~/Library/Application Support/AndroidStudioPreview3.0/Kotlin(例如,如果您使用的是Mac)。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接