Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to find aapt2 logs?

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?

like image 220
Eugene Chumak Avatar asked Jan 23 '18 11:01

Eugene Chumak


People also ask

Where is AAPT2?

You can also debug build errors related to AAPT2 from the command line. To do so, you can find AAPT2 as a standalone tool in Android SDK Build Tools 26.0.

What is AAPT file?

aapt stands for Android Asset Packaging Tool and is included in the tools/ directory of the SDK. This tool allows you to view, create, and update Zip-compatible archives (zip, jar, apk). It can also compile resources into binary assets.


1 Answers

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.


The logs do unfortunately not show up directly in the regular build window. I'm not sure why, or who thought it was a good idea, but that's how it currently works. You'll need to pop into the text-based version.

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

In this case I intentionally created a syntax error in some XML code (there are other places you can get AAPT2 errors too, like in the manifest or Kotlin, or somewhere else. This is just for the sake of demonstrating). I've highlighted a button in the image. If you hover over the button it should say "Switch view". Click it and you'll enter the text-based version of the build tab:

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

Though the syntax is slightly different:

enter image description here


The icon changed in a later version. 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.

like image 131
Zoe stands with Ukraine Avatar answered Sep 17 '22 08:09

Zoe stands with Ukraine