简体   繁体   English

在 Android Studio 3.1.3 中构建 gradle 失败

[英]Build gradle failed in Android studio 3.1.3

I'm running into this error building gradle:我在构建 gradle 时遇到了这个错误:

org.gradle.api.internal.tasks.DefaultTaskInputs$TaskInputUnionFileCollection cannot be cast to org.gradle.api.internal.file.collections.DefaultConfigurableFileCollection Possible causes for this unexpected error include: org.gradle.api.internal.tasks.DefaultTaskInputs$TaskInputUnionFileCollection 无法转换为 org.gradle.api.internal.file.collections.DefaultConfigurableFileCollection 导致此意外错误的可能原因包括:

  • Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.) Re-download dependencies and sync project (requires network) Gradle 的依赖缓存可能已损坏(有时会在网络连接超时后发生。)重新下载依赖项并同步项目(需要网络)
  • The state of a Gradle build process (daemon) may be corrupt. Gradle 构建进程(守护进程)的状态可能已损坏。 Stopping all Gradle daemons may solve this problem.停止所有 Gradle 守护进程可能会解决这个问题。 Stop Gradle build processes (requires restart)停止 Gradle 构建过程(需要重启)
  • Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.您的项目可能使用了第三方插件,该插件与项目中的其他插件或项目要求的 Gradle 版本不兼容。
In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes. 在 Gradle 进程损坏的情况下,您还可以尝试关闭 IDE,然后杀死所有 Java 进程。

build.grandle :构建.grandle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.2"

    defaultConfig {
        applicationId "com.google.android.gms.samples.vision.face.facetracker"
        minSdkVersion 19
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {

    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:support-v4:24.2.1'
    compile 'com.android.support:design:24.2.1'
    compile 'com.google.android.gms:play-services-vision:9.4.0+'
    compile 'org.apache.commons:commons-math3:3.6.1'
    compile 'com.edwardraff:JSAT:0.0.9'
}

grandle-wrapper.properties : Grandle-wrapper.properties

#Sun Sep 02 12:44:30 CEST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-all.zip

HOw could I fix it?我怎么能修好呢?

I don't know if this will work or not but replace "compile" with "implementation". 我不知道这是否行得通,而是用“实现”代替“编译”。 Check this out: What's the difference between implementation and compile in Gradle? 检查一下: 在Gradle中实现和编译有什么区别?

https://stackoverflow.com/a/39050141/8272380 Upgrade your gradle build tools to the latest version. https://stackoverflow.com/a/39050141/8272380将gradle构建工具升级到最新版本。 This is the simplest method. 这是最简单的方法。
Go to File > Project Structure > Project Tab 转到文件>项目结构>项目选项卡

After entering required version for both Gradle and Plugin press Ok. 输入Gradle和插件所需的版本后,按确定。 It will Sync modified gradle files. 它将同步修改的gradle文件。 After that you can start working with new Gradle version. 之后,您可以开始使用新的Gradle版本。

I hope this will help you. 我希望这能帮到您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM