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

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.

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:
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.
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
Save the file.
Close and re-open your android project.
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.

Here the solution to attache the source of the support library in Eclipse Juno
I suppose that your project already has android-support-v4.jar in your "Build Path", under "Android Dependencies", but you cannot attach the sources directory to it. (the "Source attachment" said "Non modifiable"). Solution:
Goto "Configure Build Path"
Add External JARs > YourProject/libs/android-support-v4.jar
(I know your project had already referenced to it but don't worry, just add it again).
Expand jar and attach Source to the External Jar: android-sdk/extras/android/support/v4/src
Switch to the "Order and Export" tab, pull up the external jar above the "Android Dependencies"
Enjoy navigating the support library with source!
if you have an "Android Test Project" attached to YourProject, so YourProjectTest might not compiled anymore. In this case, you have to return to "Order and Export" and pull down the external jar below the "Android Dependencies" to get things back to normal.

After downloading the support package from the Android SDK Manager, you can find the source code of support package in folder <android-sdks>/extras/android/support/v4/src.

Referencing the accepted answer, it is also possible to attach the source straight from the directory without building a .jar file. From the Java build path / libraries tab, expand android-support-v4.jar, highlight "Source attachment", click "Edit...", "External Folder..." then point to (android-sdk)\extras\android\support\v4.
This was tested using eclipse indigo.
From the comments:
The problem of being unable to add source to the support library seems to occur if your support library is located in the "Android Dependencies" folder of your project. The workaround is from the same "Java build path / libraries" tab click "Add External JARs..." and find the .jar file in your (android-sdk)\extras\android\support\v4 path. It will then appear in your project setup under a new "Referenced Libraries" folder.

For those who like the standard to have the jar file of the source code, which makes it more convenient for source control and sharing the project.
For example:
../android-support-v4.jar
../android-support-v4-src.jar
It is simple to create the source jar file and attach it:
cd to path_to_android_sdk/extras/android/compatibility/v4/
Use your favorite zip program such as 7-zip to create a zip file and name it android-support-v4-src.jar. The first folder in the jar should be /scr.
Copy the file to your project, in this example it is in the same folder as the code jar.
In Eclipse attach the source jar in project properties.

I just remove the auto generated one , then manual add it as a Referencde Libraries.
First open a class, the IDE will ask you to Change Attached Source.

The process of attaching the src and doc from build path works for some and it doesn't for some (like me). some key things to keep in mind
Make sure you are in Package Explorer, not Project Navigator.
If you have put your android-support-v4.jar in libs folder under your project. great.
Right click the jar, Build path.. Add to Path. (if Add to Path does not show up then its already added. you will see configure path..)
As the result of step 3, a new folder called Referenced Libraries will appear in package explorer tree. Open that tree, find the android-support-v4.jar there. Right click on this jar in the Referenced Libraries, properties. Then set the Java Source Attachment and Javadoc Location there.
You are done.
The path for my Java Source Attachment.(its external location)
C:/Users/thupten/adt-bundle-windows-x86_64-20130514/sdk/extras/android/support/v4/src
I used the android website doc for java doc location
http://developer.android.com/reference/android/support/v4/app/package-summary.html

I found this for me:
For main lib: android.jar:
src: sdk/sources/android-19
doc: sdk/docs/reference/
For support lib: android-support-v4.jar: (before this we should add android-support-v4.jar like external jar (Project Properties -> Java Build Path -> Libraries, then in Tab ‘Order and Export’ pull up this library before Android Private Libraries)):
src: sdk/extras/android/support/v4/src/java
doc: http://developer.android.com/reference/android/support/v4/app/package-summary.html (not sure)

After you have updated the SDK and downloaded Documentations in it:
Import support library project to package explorer.
Create a folder in the library and name it something like ext-jars.
Move android-support-v4.jar to ext-jars folder.
Right click on the project and click on Properties.
Click on Java Build Path in the left menu then select Libraries tab.
Click on Add JARs... then expand the project and select the jar file you already moved to folder ext-jars.
Expand the added jar and select Source attachment then click on Edit.
Select External location then click on External Folder...
Choose the source folder for the Support v4 which is located in
[sdk-path]/extras/android/support/v4/src
Select Javadoc location click on Edit then select Javadoc URL then click on Browse... and choose the javadoc location for support v4 which is located in [sdk-path]/docs/reference/
- Select Order and Export tab and check the android-support-v4.jar you just added.
I suggest you also clean the project and reopen the Eclipse.

Related

Import "MPChartLib" Library to Eclipse

I tried to add "MPAndroidChart" library in Eclipse but when I try to import this lib:(https://github.com/PhilJay/MPAndroidChart/archive/master.zip) .
Amongst the downloaded files , I found a folder called "MPChartLib". This is the actual library folder, I need to add this folder to my project to be able to use the full functionality of the library.
I tried to import the library folder into my workspace, using File-->Import-->Android-->Existing Android but I have this message " Select at least one project eclipse import" !!!!
The lib uses gradle, because of that you can't "import a eclipse project"
You have 2 options, install a gradle plugin for eclipse, or use the lib as a jar
From the lib README:
Download the latest .jar file from the releases section
Copy the mpandroidchartlibrary-.jar file into the libs folder of your Android application project
Start using the library
I hope the same named file is already there or else you can do one thing check the file name to the New Project Name column and check the same file name in your workspace. I must say you that the same named file is definitely there.
So once you will find this, just rename your file name into your workspace and try again importing this.
I hope this will work for you. Any help will be needed, do let me know.
"Select at least one project eclipse import" this message inform you that you have already added Lib in Work Space check for already added "MPChartLib" Lib followed this step:-
Write click on your project and select Properties.
On left select Android.
In Android->Library section click Add
Select for "MPChartLib" (note: name can be change).
Or If you unable to find lib please make new workspace if possible then import MPAndroidChart on workspace.

Problems including library project into build path

I am trying to follow the steps of setting up a v7 support library as they are listed on the android development website.
Create a library project and ensure the required JAR files are included in the project's build path
I get stuck on step 5 where I am supposed to right click the JAR files and choose "Build Path". This option is missing. I have checked other questions related to this such as this one>>> Question
but none of the listed solutions seem to work for me. Either that or I do not see the options that the posters are referring to on the menus. Has anyone had this problem? Where did I go wrong?
I need this for an android project.
If you are doing in eclipse, then you can go to ProjectName -> Right click on it -> Goto Properties -> Goto Java Build Path -> Go to Library -> Choose Add Jars option if jar is in same project or choose Add External JARs if jar is outside the project folder.
If you have already copied the JAR file to libs/ directory of your project then choose the option of Add JARs and browse to the libs folder where you've copied the jar. Select it and press okay. It should get included in your project. Hope this helps else please comment.

How to add source + javadoc for android-support-v7?

I added to my project support library android-support-v7-appcompat, but I can't add source and javadoc for it.
I downloaded https://android.googlesource.com/platform/frameworks/support/+/master package with source and in Eclipse I set Source attachment to v7/appcompat/, but it doesn't work.
Can someone help me?
E: my solution is, I have two projects in Eclipse "android-support-v7-appcompat" (original lib from android-sdk\extras\android\support\v7\appcompat) and "android-support-v7-appcompat-src" (src from android.googlesource.com) and when I compile release version, so I used original lib and for debug I used src from googlesource.com.
PS: sorry for my english
I was able to attach the source based on advice from How do I attach the Android Support Library source in Eclipse?.
Here's what I did:
First, clone the source repository and get whatever version corresponds to the released library (which I guessed):
git clone https://android.googlesource.com/platform/frameworks/support
cd support
git checkout android-4.3.1_r1
Next, in Eclipse:
Right-click project and choose Properties.
Select Java Build Path
Select the Libraries tab
Add External JARs > YourProject/libs/android-support-v7-appcompat.jar (I know your project had already referenced to it but don't worry, just add it again).
Expand jar and attach Source to the External Jar: WhereverYouHaveTheSource/support/appcompat
Switch to the "Order and Export" tab, move the external jar above the "Android Dependencies"
Or the same using #andr answer to How do I attach the Android Support Library source in Eclipse?
git clone https://github.com/android/platform_frameworks_support android_sources_folder
add android-support-v7-appcompat.jar.properties file into libs (next to android-support-v7-appcompat.jar) with content
src=D:\\android_sources_folder\\platform_frameworks_support\\v7\\appcompat\\src
close and reopen project
Sources for appcompat-v7 are available within "API21/Sources for Android SDK" package which can be downloaded with SDK Manager, the path is \sdk\sources\android-21\android\support\v7\
Android Studio will allow you to browse lib source code when you point this dir as appcompat-v7 source dir root.

how to include jar files in my eclipse project

I'm new to android and java. I downloaded the GSON library for use in my android project which exists in Eclipse. I lookup instructions on how to use the jar file in my project and it says...
Quote...
You can use a third party JAR in your application by adding it to your Eclipse project as follows:
In the Package Explorer panel, right-click on your project and select Properties.
Select Java Build Path, then the tab Libraries.
Press the Add External JARs... button and select the JAR file.
Alternatively, if you want to include third party JARs with your package, create a new directory for them within your project and select Add Library... instead.
It is not necessary to put external JARs in the assets folder
...UnQuote
I'm afraid that I don't know the difference between "using a 3rd party jar in my project" and "include third party jars with my package." I want to be able to use the GSON methods in my Android phone application and, of course, have the capability deployed in my .apk.
So, Which do I want to do?
Thanks, Gary
add the jar to your libs folder in your project.
open eclipse go to package explorer
right click on your project and select project properties
click on java Build path in the bar on the left hand side of the popup
select the libraries tab
select the "Add External Jar File" and navigate to your JAR file
best of luck =)
click Properties
left select Build path
Than add jar, and do not use the external libs, unless it is really required.
You have to copy the jar to your project to find it with "Add jars"
Right click onto your main project in the Project Explorer
Open properties option, found at the bottom of the context menu
A dialog box opens from which you select the Android option
Remove the old .jar file, click on ADD to add a new .jar file and select your the file you want to add
You're done!

How to use and package a JAR file with my Android app?

I have an API in the form of a JAR that I would like to use in my Android app. Not sure if it should be part of the project in Eclipse or kept separate and added to the project properties. This JAR also needs to be packaged with the application, so how is that done for Android apps?
As explained by this SO question:
Your Project -> right click -> Import -> Archive File -> yourjar.jar
Your Project -> right click -> Properties -> Java Build Path -> Libraries -> Add Jar -> yourjar.jar
You must add it as "external JAR" files, and set the "Order and Export" in your Eclipse project.
Update February 2012:
Pacerier mentions in the comment having an issue (ClassNotFound) even though he did declare the library.
He had:
However, the solution was simple:
Over 1 hour wasted. Man was I pissed!
Solution: make sure your JAR is compiled with 1.6 and not 1.7.
Argh
Thanks to VonC for pointing me in the right direction. I had the same symptoms but for a different library (I needed to add org.apache.commons.codec.binary.Base64 for an Android project). The solution that worked for me was SLIGHTLY different. Herewith the steps that I followed:
Download library from http://commons.apache.org/codec/download_codec.cgi
Extract commons-codec-1.6.jar from the tarball and copy to a local
folder
In eclipse:
right-click project name
choose "Properties" from context menu
on "Libraries" tab, select "Add External JARs..."
navigate to and select commons-codec-1.6.jar from the location you extracted it to your local drive
The jar file will now appear under "referenced Libraries" in your Package Explorer and you will be able to reference the library in your code.

Categories

Resources