Android 运行 MyActivity 时出错:Gradle 项目同步失败。请修复您的项目,然后重试

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24778598/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 08:45:03  来源:igfitidea点击:

Error running MyActivity: Gradle project sync failed. Please fix your project and try again

androidandroid-studiogradleandroid-gradle-plugin

提问by Jaskey

I am new to Android Studio and I have just created a new project with only one Activity with fragments(Android studio created that), and when I ran the MyActivity.java , error occurs:

我是 Android Studio 的新手,我刚刚创建了一个只有一个 Activity 和 Fragment 的新项目(Android Studio 创建的),当我运行 MyActivity.java 时,发生错误:

Error running MyActivity: Gradle project sync failed. Please fix your project and try again.

Nothing more in my event log.

我的事件日志中没有更多内容。

I have no idea why it is, and This linkdid not helps.

我不知道为什么会这样,这个链接没有帮助。

One clue is that Gradle project sync in progress is flowing all the time , just after I restart the Studio.

一个线索是正在进行的 Gradle 项目同步一直在流动,就在我重新启动 Studio 之后。

回答by shikhar bansal

  1. Goto File -> Invalidate caches / Restart
  2. Shutdown Android Studio
  3. Rename/remove .gradle folder in the user home directory
  4. Restart Android Studio (It will download gradle metadata and data)
  5. Gradle build succeed
  6. Rebuild project
  7. Done
  1. 转到文件 -> 使缓存无效/重新启动
  2. 关闭 Android Studio
  3. 重命名/删除用户主目录中的 .gradle 文件夹
  4. 重新启动 Android Studio(它将下载 gradle 元数据和数据)
  5. Gradle 构建成功
  6. 重建项目
  7. 完毕

回答by badaboomskey

The exact same error message also pops up if there is a syntax-error inside your AndroidManifest.xml file. So if the above won't work - which it didn't for me - then check the AndroidManifest.xml syntax. That will save you thousands of frustrating hours.

如果 AndroidManifest.xml 文件中存在语法错误,也会弹出完全相同的错误消息。因此,如果上述方法不起作用 - 这对我来说不起作用 - 然后检查 AndroidManifest.xml 语法。这将为您节省数以千计令人沮丧的时间。