Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are comments removed from final apk?

Tags:

java

android

If comments in java files are removed as part of apk creation, how the log statements are able to print the correct line number? Could someone please explain? I have seen the same behavior in java files as well when they are compiled.

like image 593
Raghav Avatar asked Sep 06 '25 03:09

Raghav


1 Answers

Comments are not preserved in the APK. The APK contains the compiled byte code for the classes in your application and this byte code does not contain source code comments.

The byte code does preserve some information about the source code, such as method names, to be used when generating stack traces. This may, or may not include accurate line numbers. See:

How can we print line numbers to the log in java

Why some stacktrace do not have line number in java

like image 90
Malcolm Smith Avatar answered Sep 08 '25 00:09

Malcolm Smith