12

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?

Community
  • 1
  • 1
Eugene Chumak
  • 3,272
  • 7
  • 34
  • 52
  • See in the right bottom edge "Gradle Console" tab. – azizbekian Jan 23 '18 at 11:46
  • No problem there: https://i.gyazo.com/5112ae4bbefdcf36b861acf341f442c6.png Gradle builds fine. The problem occurs when I try to assemble apk. – Eugene Chumak Jan 23 '18 at 11:52
  • @EugeneChumak what do you mean by 'trying to assemble the apk'? Whenever you build your project (be it by 'Run 'app'', 'Make Project', 'Rebuild Project' or 'Build APK(s)') the build happens through Gradle and the output of the build is in the Gradle Console tab like azizbekian mentioned already. If you're getting an error, this is where the logs and the details will be. If you're still having trouble go to the project directory and run "./gradlew clean assembleDebug >> out.txt" and post the contents here. – Izabela Orlowska Jan 23 '18 at 14:22
  • By "assemble the apk" I mean Build -> Make Project. It seems, the problem was in wrong run configuration. When I started building, gradle console just didn't update, so I saw results of the previous build. – Eugene Chumak Jan 23 '18 at 16:39

1 Answers1

8

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.

Zoe
  • 27,060
  • 21
  • 118
  • 148