简体   繁体   English

为什么 Android Studio 构建失败,图像上出现 AAPT2 错误?

[英]Why is Android Studio failing to build, with an AAPT2 error on images?

After a recent update, Android Studio fails to build an unmodified project with errors along these lines:最近更新后,Android Studio 无法构建未修改的项目,并出现以下错误:

> 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.

Notice that it's failing on an image supplied by Android Studio itself!请注意,它在 Android Studio 本身提供的图像上失败了!

What can I do to fix it?我能做些什么来修复它?

This seems to be an error in the newest (newer?) Gradle plugin(s) when it comes to PNG images;当涉及 PNG 图像时,这似乎是最新(较新?)Gradle 插件中的错误; Google's IssueTracker lists several newly reported bugs along these lines. Google 的 IssueTracker 列出了几个新报告的错误。 One of them mentions that it's a Gradle issue;其中一个提到这是一个 Gradle 问题; I made mine work by reverting to a previous version: Gradle Plugin 4.0.1 and Gradle version 6.1.1 work fine.我通过恢复到以前的版本来完成我的工作:Gradle Plugin 4.0.1 和 Gradle 版本 6.1.1 工作正常。

It will be necessary to ignore AS' nagging about a newer version until this gets fixed.在解决此问题之前,有必要忽略 AS 对新版本的唠叨。

[Added at the request of @YinOrYan] [应@YinOrYan 的要求添加]

To revert to an older version of Gradle:要恢复到旧版本的 Gradle:

  1. In the menu, select "Files", then "Project Structure..."在菜单中,选择“文件”,然后选择“项目结构...”
  2. In the dialog that pops up, select "Project" (first item in my version).在弹出的对话框中,选择“项目”(我的版本中的第一项)。
  3. You can select the desired versions of the Gradle plugin and of Gradle from the drop-down menus.您可以从下拉菜单中选择所需版本的 Gradle 插件和 Gradle。

This should not lose any system calls, as this is different from the SDK or API versions.这不应丢失任何系统调用,因为这与 SDK 或 API 版本不同。 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.像往常一样,当您第一次构建时,或者每当您必须导入依赖项时,您都会希望在线,但否则应该可以离线工作。

Sadly, it looks like an issue with older architectures.可悲的是,它看起来像是旧架构的问题。 While the team at Google is looking into fixing it, in the meanwhile you can still use the new Android Studio and AGP, but temporarily revert to using an older version of AAPT2:虽然 Google 的团队正在考虑修复它,但同时您仍然可以使用新的 Android Studio 和 AGP,但暂时恢复使用旧版本的 AAPT2:

Try locating the old aapt2 executable in your gradle cache, eg: ~/.gradle/caches/<subdirectories, hashes etc>/aapt2-4.1.0-alpha03-6246747-/aapt2(.exe)尝试在您的 gradle 缓存中找到旧的 aapt2 可执行文件,例如:~/.gradle/caches/<subdirectories, hashes etc>/aapt2-4.1.0-alpha03-6246747-/aapt2(.exe)

Once you have the path you can add to your gradle.properties file: android.aapt2FromMavenOverride=path/to/old/aapt2获得路径后,您可以将其添加到 gradle.properties 文件中: android.aapt2FromMavenOverride=path/to/old/aapt2

To make this a little bit more robust you can actually copy that executable to a non-cache location, in case you clean your caches and it dissapears.为了使它更健壮一点,您实际上可以将该可执行文件复制到非缓存位置,以防您清理缓存并使其消失。

Hope this helps!希望这可以帮助! Keep an eye on the Issue Tracker bug for updates.请密切关注问题跟踪器错误以获取更新。

I also had the same problem with AAPT2 errors and I have got over it.我也遇到了与 AAPT2 错误相同的问题,我已经解决了。

First, downgrades Gradle to version 4.0.1, or首先,将 Gradle 降级到 4.0.1 版,或者

Second, I have done is upgrading the AMD Athlon processor to AMD FX-4300 without downgrading the gradle plugin version.其次,我所做的是在不降级gradle插件版本的情况下将AMD Athlon处理器升级到AMD FX-4300。

Wow, that's a real show-stopper!哇,这真是个大秀! Can you explain how you reverted to an older gradle in Android Studio.你能解释一下你是如何在 Android Studio 中恢复到旧的 gradle 的。 Is it possible to work offline after doing this.这样做后是否可以脱机工作。 And, did you lose any of the new system calls as a result?而且,您是否因此丢失了任何新的系统调用? All this going on after finally getting my code working with the new AR Core stuff...在最终让我的代码与新的 AR Core 东西一起工作之后,所有这一切都在发生……

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM