gradle之错误 : DefaultOperationDescriptor@2b878eea already available in Android Studio

itcoder 阅读:106 2024-12-31 21:38:35 评论:0

未能完成 Gradle 执行

当我尝试将 Gradle 与项目文件同步时,出现下面提到的错误

我使用的Android Studio版本是3.0.1,Gradle Build 4.1-all.zip

仅供引用,我已经尝试过 ->Build->Clean Project and Invalidate Cache & Restart 还有一件事是我的代码没有错误。

消息错误:

Information:Gradle tasks [:app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:mockableAndroidJar] Error:Failed to complete Gradle execution.

Cause: Operation org.gradle.tooling.internal.provider.events.DefaultOperationDescriptor@86028ba already available.

BUILD SUCCESSFUL in 8s

Information:1 error

Information:0 warnings

但是当我尝试在我的模拟器上运行时

出现如下错误

运行时消息错误

Information:Gradle tasks [:app:assembleDebug] E:\Android Game App\app\build.gradle Error:(1, 1) A problem occurred evaluating project ':Android Game App:app'. Failed to apply plugin [id 'com.android.application'] Due to a limitation of Gradle new variant-aware dependency management, loading the Android Gradle plugin in different class loaders leads to a build error. This can occur when the buildscript classpaths that contain the Android Gradle plugin in sub-projects, or included projects in the case of composite builds, are set differently. To resolve this issue, add the Android Gradle plugin to only the buildscript classpath of the top-level build.gradle file. In the case of composite builds, also make sure the build script classpaths that contain the Android Gradle plugin are identical across the main and included projects. If you are using a version of Gradle that has fixed the issue, you can disable this check by setting android.enableBuildScriptClasspathCheck=false in the gradle.properties file. To learn more about this issue, go to https://d.android.com/r/tools/buildscript-classpath-check.html. Information:BUILD FAILED in 16s Information:1 error Information:0 warnings Information:See complete output in console

在 Google 上找不到任何内容!非常鼓励任何帮助???

请您参考如下方法:

问题的关键是这一行。可能是由于根目录 build.gradle 中的 project.all 或您正在使用复合构建。

This can occur when the build script classpaths that contain the Android Gradle plugin in sub-projects,  
or included projects in the case of composite builds, are set differently. 

这意味着在你所有的 build.gradle 中你有不止一条这条线

buildscript { 
    dependencies { 
        classpath "com.android.tools.build:gradle:x.y.z" 
    } 
} 

这意味着随着 Android Gradle Plugin 3.Y.Z 的引入和 handling dependencies 的新方式, 如果您在同一个项目中混合使用不同插件版本的 2 个项目(一个是 2.3,另一个是 3.0.1),您将在编译时获得龙。

这个错误是一种强制开发人员检查它并在检测到并解决后选择退出的方法。

如何解决,首先确保你没有使用低于 3.0.1 的 android gradle 插件并使用新的依赖配置,并在你拥有的每个 gradle.properties 上添加此属性。

android.enableBuildScriptClasspathCheck=false 

这样你就可以编译了

可以在 realm sample repo 找到一个示例他们使用一个 allprojects block ,在每个模块上都包含 android gradle 插件。并解决它在根目录下添加 previus gradle 属性 gradle.properties


标签:Android
声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

关注我们

一个IT知识分享的公众号