How to resolve Execution failed for task ':app:mergeDebugResources'. in android studio 3.6.2

huangapple go评论82阅读模式
英文:

How to resolve Execution failed for task ':app:mergeDebugResources'. in android studio 3.6.2

问题

我在Android Studio中创建了我的第一个项目并设置了模拟器,但当我运行应用程序时,出现了以下错误并且构建输出失败。我该如何修复这个问题?

英文:

I created my first project in Android Studio and set up emulator but when I run the application I get the error below and the build output: build failed. How can I fix this?

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:mergeDebugResources'.
> Could not resolve all files for configuration ':app:_internal_aapt2_binary'.
   > Could not resolve com.android.tools.build:aapt2:3.6.2-6040484.
     Required by:
         project :app
      > No cached version of com.android.tools.build:aapt2:3.6.2-6040484 available for offline mode.
      > No cached version of com.android.tools.build:aapt2:3.6.2-6040484 available for offline mode.

答案1

得分: 2

我找到了解决我遇到的错误的方法(与你的完全相同)。这可能发生在我更新了Android Studio时... 下面是我所做的,它起作用了:

打开任何项目,然后选择“文件” > “项目结构...”(或使用快捷键Ctrl+Alt+Shift+S)。转到刚刚出现的窗口的项目部分(位于顶部),选择最新版本的Android Gradle插件(等于Android Studio版本)和Gradle(现在是Android Studio 3.6.2和Gradle 6.3)。完成后点击:“应用” 和 “确定”。

第二件要做的事情:“视图” > “工具窗口” > “GRADLE”。在刚刚打开的窗口中,点击“切换离线模式”,窗口顶部的倒数第二个图标(它不应该再被高亮显示),然后保持这个窗口一段时间。现在构建你的项目/创建apk文件以运行Gradle并下载所需内容,因为你已经改变了版本(将你的电脑连接到互联网!)。

通常情况下(至少对我来说),Android Studio会下载所需内容,你只需稍等片刻。一旦构建完成,返回到Gradle窗口,重新激活“切换离线模式”(它必须被高亮显示)。重新构建你的项目以确保它工作正常(我不知道这一步是否必要,但过多总比过少好!),然后你就完成了!不会再有错误,也不需要连接到互联网了!

英文:

I found the answer to the error I got (exactly the same as yours). It probably happened when I updated Android Studio... Here's what I did and it worked:

Open any project, and do "FILE" > "PROJECT STRUCTURE..." (or the shortcut Ctrl+Alt+Shift+S). Go to the project section (at the very top) of the window that just appeared and choose the latest version of Android Gradle Puglin (= Android Studio version) and Gradle (now it's 3.6.2 for Android Studio and 6.3 for Gradle). Once done: "APPLY" & "OK".

Second thing to do: "VIEW" > "TOOL WINDOWS" > "GRADLE". With the window that just opened, click on "TOGGLE OFFLINE MODE", the penultimate icon at the top of the window (it must not be highlighted anymore), and keep this window for a little while. Now build your project/create the apk file to run Gradle and download the necessary, since you have changed version (Connect your pc to the internet!).

Normally (at least for me), Android Studio will download what you need and you'll just have to wait a bit. As soon as the build is finished, go back to the Gradle window and reactivate "TOGGLE OFFLINE MODE" (it must be highlighted). Rebuild your project to make sure it works (I don't know if this step is necessary, but better too much than too little!), and you're done! No more errors and no more need to connect to the Internet!

答案2

得分: 0

这些资源需要安装,无法离线同步,因此您需要连接到互联网,然后再次同步 build.gradle,以便下载这些资源。
希望这能帮助您。

英文:

These resources need to be installed and it can't be synced offline so you need to connect to internet and then sync build.gradle again in order to download these resources.
Hope this will help you.

答案3

得分: 0

错误消息在我更改文件名和文件类型后出现。

我尝试过:

> 构建> 清除构建,以及
> 构建 > 重新构建

两者都没有生效。

尽管通过"与Gradle文件同步项目",错误被移除了。

注意:我使用的是Android Studio Electric Eel | 2022.1.1

同时,在我意识到我在我的constraint xml中移除了tools:.MainActivity后,它就起作用了。

英文:

The error message happened to me after I changed file names and file types.

I tried:

> Build> Clear Build, and
> Build > Rebuild

Both didn't work.

Although "Sync Project with Gradle Files" removed the error.

Note: I'm using ANdroid Studio Electric Eel | 2022.1.1

Also, it worked when I realised I have removed tools:.MainActivity on my constraint xml.

huangapple
  • 本文由 发表于 2020年4月4日 22:05:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/61029292.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定