Connecting Android sources in Eclipse

  • Tutorial
Just yesterday I came across a simple and, it would seem, such an obvious function in the Eclipse IDE as connecting sources from external libraries. Perhaps this may seem too simple and banal to someone, but having interviewed several familiar developers, I found that not only I did not know about such a function, therefore, for all fans and professionals who are developing for Android, I ask for a cut, and you will find out how to debut not only your code, but look “at the root” - namely, debut your project “to the bottom”.

I think this picture is fed up with any Android developer (and not only). How disappointing it is to look for an error for a long time, to monitor the variables and the progress of the application execution, in order to finally find out that the error occurs in a place that is invisible to you and, therefore, completely beyond control and, most likely, incomprehensible.

It turns out that the developers of Eclipse and Android provided an excellent opportunity to see the sources of our libraries (if they exist, of course) and use them to their full potential. This does not apply to cases when the library in the sources is imported as a separate project. All of the following applies to the case when the library is in the jar-file (this is how the Android API or JDK library is connected).

Well, let's begin. We right-click on our project in the Package Explorer and look for the Propreties item (at the very bottom).

Open the properties as shown in the picture and click Edit .

In the menu that opens, select External folder and look for the folder with the Android sources (in the% android_sdk% / sources / android-% api_version% folder. If there are no sources, start the SDK Manager and download the Sources for Android SDK corresponding to the Target API of your project. As a result, we get just such a thing:

Save the settings, right-click on the project folder again and select Resresh , and now try to hold Ctrl and left-click on any Android class in the text of your program. I chose the Activity class as a victim .

This way you can connect source codes (and with them or instead of them Java-doc) to any library that provides one or the other as a file or archive. For example, the ORMLite library producessource codes and Java-docs that connect in exactly the same way.

That's all. As you can see, this is all done very quickly. And from now on, if the behavior of your hand robot becomes mysterious for you, you have a great opportunity to understand the reasons for this behavior, and at the same time to study a bit of the source of the OS, which will only be an additional plus in any case.

PS In a completely similar way, you can connect the JDK sources if you work purely in Java. To do this, the file located in the root of the folder where your JDK is installed must be connected to the rt.jar library as sources.

From the author: I sincerely hope that this will help many newcomers (and not only) to get used to the Android system better.

Also popular now: