为什么 Android Studio 构建失败,图像上出现 AAPT2 错误? [英] Why is Android Studio failing to build, with an AAPT2 error on images?

查看:79
本文介绍了为什么 Android Studio 构建失败,图像上出现 AAPT2 错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近更新后,Android Studio 无法构建未修改的项目,并出现以下错误:

After a recent update, Android Studio fails to build an unmodified project with errors along these lines:

> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade

  > AAPT2 aapt2-4.1.1-6503028-linux Daemon #0: Unexpected error during compile '/path/to/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png', attempting to stop daemon.
    This should not happen under normal circumstances, please file an issue if it does.

请注意,它在 Android Studio 本身提供的图像上失败!

Notice that it's failing on an image supplied by Android Studio itself!

我能做些什么来修复它?

What can I do to fix it?

推荐答案

当涉及到 PNG 图像时,这似乎是最新(较新?)Gradle 插件中的错误;Google 的 IssueTracker 列出了几个新报告的错误.其中一个提到这是一个 Gradle 问题;我通过恢复到以前的版本来完成我的工作:Gradle Plugin 4.0.1 和 Gradle 版本 6.1.1 工作正常.

This seems to be an error in the newest (newer?) Gradle plugin(s) when it comes to PNG images; Google's IssueTracker lists several newly reported bugs along these lines. One of them mentions that it's a Gradle issue; I made mine work by reverting to a previous version: Gradle Plugin 4.0.1 and Gradle version 6.1.1 work fine.

在此问题得到解决之前,有必要忽略 AS 对更新版本的唠叨.

It will be necessary to ignore AS' nagging about a newer version until this gets fixed.

[应@YinOrYan 的要求添加]

要恢复到旧版本的 Gradle:

To revert to an older version of Gradle:

  1. 在菜单中,选择文件",然后选择项目结构..."
  2. 在弹出的对话框中,选择项目";(我的版本中的第一项).
  3. 您可以从下拉菜单中选择所需的 Gradle 插件和 Gradle 版本.

这不应丢失任何系统调用,因为这与 SDK 或 API 版本不同.但是,它不是独立它们,因此您可以设置它们的位置可能有限制.

This should not lose any system calls, as this is different from the SDK or API versions. However, it's not independent of them, so there is probably a limit to where you can set them.

像往常一样,当您第一次构建时,或者每当您必须导入依赖项时,您都会希望在线,但否则应该可以离线工作.

As usual you will want to be online when you first build, or whenever you have to import a dependency, but otherwise it should be possible to work offline.

这篇关于为什么 Android Studio 构建失败,图像上出现 AAPT2 错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆