Android Studio 3.0 Canary 5中的Gradle同步失败

3
这是我的build.gradle(Project: MyProjectName)文件:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    ext.kotlin_version = "1.1.1"
    ext.supportLibVersion = "25.3.0"

    repositories {
        jcenter()
    }

    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"

        classpath 'com.android.tools.build:gradle:3.0.0-alpha5'

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

allprojects {
    String osName = System.getProperty("os.name").toLowerCase();

    if (osName.contains("windows")) {
        buildDir = "C:/tmp/${rootProject.name}/${project.name}"
    }

    repositories {
        jcenter()
    }
}

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

以下是build.gradle(Module:app)文件的内容:

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

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"

    defaultConfig {
        applicationId "com.example.android.datafrominternet"
        minSdkVersion 10
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:25.1.0'

    // TODO (32) Remove the ConstraintLayout dependency as we aren't using it for these simple projects
    compile 'com.android.support.constraint:constraint-layout:1.0.0-beta4'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7: $kotlin_version"
}

这是错误信息:

Error:Unable to find method 'com.android.build.gradle.internal.variant.BaseVariantData.getOutputs()Ljava/util/List;'.

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

  1. 把你的kotlin版本升级到1.1.2:Kotlin 1.1.2也与Android Gradle插件2.4.0-alpha版本兼容。
  2. 我建议你使用android gradle插件3.0.0-alpha4而不是3.0.0-alpha5,因为最新版本有很多bug。
- DeKaNszn
谢谢您的回复。我按照您说的做了,但现在出现了另一个错误。错误:无法找到com.android.tools.build:gradle:3.0.0-alpha4。 - logdev
请查看此链接:https://stackoverflow.com/questions/44943890/error-after-sdk-update/44943945#44943945 - DeKaNszn
在 buildscript > repositories 中添加了 google(),现在我收到了与我在问题中提到的相同的错误。 - logdev
如果您依赖于开发,请回退到Android Studio 2.3并等待Google解决此问题。 - behelit
显示剩余2条评论
2个回答

4
更新Android Studio到beta-v5后遇到同样的问题。 请检查您的app/gradle文件。可能存在阻塞-->的问题。
buildscript {
repositories {
    mavenCentral()
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:3.0.0-beta5'
}

然后检查您的 app/gradleproject gradle 中的 Gradle 插件版本。 或者尝试将此代码块添加到 app/gradle 的顶部。


3
在项目的 build.gradle 文件中,修改为:
ext.kotlin_version = '1.1.2-4'

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