Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I attach the Android Support Library source in Eclipse?

Having the source code attached to external libraries is awesome. Where do I find the source code for the v4 support package? Preferably, it would be a zip file which could be easily attached to the android-support-v4.jar in Eclipse.

like image 475
Håvard Geithus Avatar asked Dec 17 '11 06:12

Håvard Geithus


People also ask

What is Android Design Support Library?

The Design Support library adds support for various material design components and patterns for app developers to build upon, such as navigation drawers, floating action buttons (FAB), snackbars, and tabs. The Gradle build script dependency identifier for this library is as follows: com. android.

What Is Legacy Library Android?

Official Description: The Support Library is a static library that you can add to your Android application in order to use APIs that are either not available for older platform versions or utility APIs that aren't a part of the framework APIs. Compatible on devices running API 14 or later.


1 Answers

I just want to add yet another method of attaching sources for the support library. It requires ADT in version 20 or later. Supposedly this method works for all JARs for which setting source/javadoc location is disabled by the container. Here's what you need to do:

  1. The android-support-v4.jar library lies in the libs directory of your project. In that same directory create a regular Java properties file named exactly like the JAR in question, but with appended .properties extension. So, for our support library it'll be:
    android-support-v4.jar.properties.

  2. Open created properties file and set value of property named src to the location where sources for that library can be found. Your file should have one line like:

    src=c:/apps/adt-bundle-windows-64bit/sdk/extras/android/support/v4/src 
  3. Save the file.

  4. Close and re-open your android project.

  5. Try browsing to one of the support classes. The source attachment should work now.

Worked perfectly in my case.

One thing to note: if src is not an absolute path, it will be resolved starting in the parent directory of the JAR file. Taking support library as an example - if src=support/src, ADT will assume that the class sources are located in libs/support/src.

Short description of this feature written by its author can be found here.

If anyone is interested in how exactly this .properties file is processed, I recommend reading patch set #4, esp. changes in eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/ internal/project/LibraryClasspathContainerInitializer.java :)

Edit

Please also see a fine comment by WindRider about adding sources properly in a project with multiple referenced libraries.

like image 158
andr Avatar answered Sep 28 '22 00:09

andr