Where to find aapt2 logs? - android

When I try to build my project, I get the following error:
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.
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:
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:
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:
Though the syntax is slightly different:
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":
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.

Related

Android Studio shows symbols in red but it compiles OK

The wise ones suggest dramatic solutions. Is there any harm happening? can I hope that it will recover all by itself. Is this a "cloud no bigger than a man's hand" coming to engulf my project in a terrible storm?
There are 3 cases that i can think about :
1)You have got some kind or warning for example :
Lets say that you are using google maps and want to add "current location button" - if you wont check if the user accepted location permission or not you will be able to run your app but you will have a warning in red line.
2)If some view is marked in red but everything compile with no errors , this is some error and cleaning and rebuilding your project should fix this
3)If some file name is marked as red , there may be some error/warning inside that file itself(for example - XML error inside some layout that allow yo to compile your app)
#user462990 If you can't see any obvious issues. I'd suggest the static analyzer Lint tool. It inspects your code and would give you a detailed report of all issues wrong with your project.
Just go to Analyze->Inspect Code.
In the Specify Inspection Scope dialog that appears select Whole project.
Lint inspects your code without building it and gives you a report of all the issues in the Inspection Result tool window at the bottom.
Clicking on any of those issues takes you to the editor at the exact line of code where the issue occurred.
See below captain Lint reporting for duty 💪.
What's the problem...
It's the color of the "R" now it's red, it was . always black before.
I compressed the project and re-opened it again and the viewPager which was red is now black.

Fidelity warning Rendering Issue

I have faced a problem when creating project in Android Studio 2.2
When trying to create xml layout, I get following warning:
When click to Show, I get the following error
How can I fix this?
It's just a warning, indicating that some details might not be rendered, not an error. It's a problem of the layout preview in Android Studio. It doesn't affect the final app at all. You can continue your work fearlessly It is just showing some of the components may not be accurate as you have set them in the xml file, but in reality, that view may possess some animation. Just press "Ignore all fidelity warnings for this session" so that you won't be disturbed with this warning again during your current work session.

How do you debug successfully in Android?

I understand there is the LogCat view to check the messages logged but I can't make sense of it.
When debugging (I use Java primarily) I've been accustomed to stepping over each line of code and finding out the exact point where the program crashes and then doing something about it.
How can I do this with Android development? Is there a way to precisely locate the line which is causing the application to crash?
I can't understand what to make of/how to read the LogCat messages and when I try to step over (using the F9 key or the 'Debug' option in Eclipse) it keeps opening new tabs for inbuilt classfiles (like Instrumentation.class etc) and after pressing F6 a few times over again the app crashes showing 'The application has stopped unexpectedly. Please try again'
Can someone tell me if there's something to be done in a way that I'm not doing here?
Thanks!
Btw if it helps, here's the generated log:
http://pastebin.com/EaqaWUdS
You are using a resource id that doesn't exist at line : 93 of com.site.custom.ModAdapter.getView(CustomListProjectActivity.java
--EDIT : add explanations
You will read a logcat stack trace in the same way as you did in Java : read bottom up and the culprit is the last line of your classes (before the code gets into the android sdk code).
You can do it the other way around, and start from top, stopping at the first class of yours and discarding android classes.
The same reasoning applies when debugging : step into your methods if needed and step over all methods of the SDK unless you want to debug them (and usually you don't, if you really suspect a bug inside the SDK, check the source at grepcode to see the inner mechanics of the android sdk class you are interested in).
Sometimes it gets difficult to track bugs on android, especially for widget layout related bugs because you can only see the code that is executed by the android platform, no code of your is executed, only your data are read from an xml file for instance. If something breaks here, it can be harder to debug. In that case, apply the dichotomy method : remove half line, if the bug doesn't show up, then readd your lines, remove half of them, etc...
It is the same like in java. Basically you need the sources to open the java files instead the class files. Google shows you how to add the sources.
Basically you debug android while staying in your own classes. I barely look into the android classes as the most issues are, of course, located in my own classes.
So just debug like you already do but don't step into methods/classes you don't own unless you have the sources added to your sdk. Even if you have, there might be some classes that aren't open source, so you can't step into the sources there. (Basically all Google API classes)

Android XML Editor: Don't notice error/warning. Just Red Hightlight

I'm using Eclipse for programming on Eclipse. Few days ago, I have installed many features of Enterprise Edition of Eclipse. When I program on Android and use Android Layout Editor again, I meet many strange thing:
1) I cannot reiceive error/warning. For example, when you use: android:text="stackoverflow", Eclipse will warnning: use should use String resource at Left panel (maybe x or !). But, I cannot see it now :(
#: hightlight as you see on StackOverFlow, but instead blue, it's red :D
2) Instead of warning/error, I will hightlight red at that line. for example: android:text="stackoverflow". And it's very difficult to me to follow.
I think maybe some config change, but when go to Windows\preference\android\Editor: I still cannot see any categories can fix it.
Please help me.
thanks :)
I'm not quite sure what you mean, but I'm assuming that you are no longer seeing warnings or error notifications in the XML editor. Check your settings at Window -> Preferences -> Android -> Lint Error Checking. Some error messages might have been set to Ignore. Any warnings or errors you want to see, you should set to either Error or Warning.
Take a look at Warnings in xml resources. This might point you in the right direction and give you visual cues.

Android - Having a hard time debuging Eclipse

I am a little bit new to developing for Android using Eclipse (Coming from a .NET/Visual Studio background).
My biggest problem in developing Android app is "debugging" them. Every time the emulator throws an error, there is no message, no explanation of what caused the error. I basically have to keep doing trial/error until something works.
My question is: Is there a better way to analyze the error messages that emulator shows (basically some stack trace about Dalvik)!
Also, is it possible in Eclipse [when debugging] to move the debugging cursor backwards to re-evaluate a variable or "skip" some lines of code?
Use LogCat view to see error/debugging messages. Regular console is of very limited help. Window->Show View->Other->Android->LogCat There on the top you will see some round buttons that basically can filter log from V (verbose) to E (error). You can't copy/paste from theLogCat window but you can save selected output to text file
Regarding the error messages (I'm assuming these are the messages that show up in LogCat): I've found that analysing the error messages and working your way up the list until you reach code that is yours is the most effective way to work. Frequently (for me at least) the emulator will crash and break somewhere in the OS code (which you probably don't have the source for) but you can follow the LogCat messages back to your code and start to see where the problem is. The crash may appear to happen in the OS code, but the original cause is typically you passing something wrong to the OS.
Regarding going backwards in code: nope, at least not with the my Eclipse Ganymede install
Regarding skipping code: When your in debug mode under the Run menu you can select "Step Over" (skips going into a method) , "Step Return" to exit a method and "Run to Line" in addition to setting Breakpoints by right clicking. This causes the code to run, but you aren't single stepping through it. Otherwise the only way to "skip" lines of code is to comment it out. I believe you can also change the value of variables in the debugger, but I've never tried personally. This may give you the desired effect.
Try closing all unrelated project, switch off eclipse and then do a clean and build for the project in picture.

Categories

Resources