Android Studio Gradle Error at Compile Time

2019-01-22 18:14发布

问题:

I have an Android App in Android Studio. When I build project with Gradle File,it gives me one error at compile time. Error Report:

Error:org.gradle.api.internal.changedetection.state.DefaultFileCollectionSnapshotter$FileCollectionSnapshotImpl cannot be cast to
org.gradle.api.internal.changedetection.state.OutputFilesCollectionSnapshotter$OutputFilesSnapshot

Please Give me solution about this error.

回答1:

1.delete {project dir}/.gradle/{gradle distribution version dir}

{gradle distribution version dir} is whatever the gradle distribution version you use (ref: https://developer.android.com/studio/releases/gradle-plugin.html#revisions). For example, it can be "1.9" or "2.10" or some other version number.

2.Sync Project with Gradle File



回答2:

This is what worked for me:

Android Studio -> File -> Invalidate Caches and Restart



回答3:

Stoping the gradle daemon worked for me.

  • go to terminal and run ./gradlew --stop
  • Rebuild the project.


回答4:

For me, I have tried to:

(Doesn't Work):

  1. invalidate caches.

  2. stop third-party plugins.

  3. remove gradle repository.

  4. remove {project dir}/.gradle/2.*(which are not current gradle version)

(Work):

Finally, the answer is like @MAC113's,

delete {project dir}/.gradle/2.10 (2.10 is my current gradle version)



回答5:

None of those solutions working for me. I ended up by:

  • Clone my project to a new folder
  • Remove .gradle, .idea folders
  • Add as a new project (File > Open > [new folder])

It works! It's a weird issue that I've ever met.



回答6:

Easy solution! Just fixed on my side. It was a project exported from Unity Studio.

After exporting from Unity, the gradle was like com.android.tools.build:gradle:2.1.0

I then changed it to com.android.tools.build:gradle:2.2.0 and it worked.

Also never forget to change the repositories from mavencenteral to jcenter().

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.3'
    }
}