When I try to build my project, I get the following error:

enter image description here

In the end it is stated: "check logs for details". Where to find those aapt2 logs?

推荐答案

NOTE: regarding disabling AAPT2, it's not a good idea. AAPT is now deprecated and will be removed by the end of 2018. Disabling it just delays the problems you'll have to fix either way when AAPT is deprecated and removed.


遗憾的是,日志(log)不会直接显示在常规构建窗口中.我不知道为什么,也不知道谁认为这是个好主意,但这就是目前的工作方式.您需要弹出到基于文本的版本.

Using AS 3.1 (possibly 3.0 as well, I'm using 3.1 so I can't test there) or IntelliJ 2018.1, you open the build tab:

enter image description here

在本例中,我故意在一些XML代码中创建了一个语法错误(在其他地方也可以得到AAPT2错误,比如在 list 或Kotlin中,或者其他地方.这只是为了演示).我突出显示了图像中的一个按钮.如果将鼠标悬停在按钮上方,则应显示"切换视图".单击它,您将进入"构建"选项卡的基于文本的版本:

enter image description here

In this case I set an XML property to a non-existent value. The actual problem is formatted as JSON (see the content of the red circle). Inside the pink one is the actual error message (resource not found), the blue circle contains the file (in this case label_layout.xml) and content of the black circle contains the location (line 4).

What the actual error is will vary from time to time, so I'm not going to add how to solve it, because there's a wide range of different problems that could be the cause. Most of the time it's your code (so far I haven't seen any cases where AAPT2 crashes or has a bug that prevents compiling). Actually solving these issues get a lot easier with decent log output.


For reference, the same applies to compilation errors:

enter image description here

虽然语法略有不同:

enter image description here


图标在更高版本中发生了更改.I will not be keeping active updates of the icon itself beyond this

For future reference: hover over the buttons in the build window until you find one that says "Toggle view":

enter image description here

That is the button you're looking for, regardless of what icon Google decides to use for it in future versions of Android Studio - at least until they fix the issues.

Kotlin相关问答推荐

Kotlin中的增广赋值语句中的难以理解的错误

Kotlin多平台(KMP)保存到文件不能在iOS上保存

T和T有什么区别:任何>

用vararg替换列表的设计弃用警告

Gradle:无法创建 ExtensiblePolymorphicDomainObjectContainer

Eclipse:无法安装 Kotlin 插件

PRDownloader 即使在实现库后也无法工作.未知参考:Android Studio 中的 PRDownloader

如何在 Kotlin for Android 上使用setTextColor(hexaValue),

Kotlin 静态函数:伴生对象,@JvmStatic @JvmField

API 'variant.getJavaCompile()' 已过时

Kotlin - 覆盖方法中的 IllegalArgumentException

如何在MVVM架构中观察RecyclerView适配器中的LiveData?

添加抽象的私有getter和公共setter的正确方法是什么?

如何在特定条件下清除jetpack数据存储数据

kotlin 委托有什么用?

Dagger +Kotlin 不注入

Jetpack Compose 折叠工具栏

Android:Exoplayer - ExtractorMediaSource 已弃用

旋转 kotlin 数组

尾随 lambda 语法(Kotlin)的目的是什么?