New version of ADT r17 plugin for Eclipse added feature to automatically setup JAR dependencies. Any .jar files in the /libs folder are added to the build configuration now. Unfortunately Android Dependencies classpath container is non modifiable.
How can i attach javadoc and sources to the automatically inserted .jar (from /libs folder)?
The best way to answer your question is to summarize the answers from Xavier, plastiv, VinceFR and Christopher.
Step by step guide
In order to link the sources and javadoc to a .jar library that is automatically linked by Eclipse you have to do the following:
Place the library .jar file in the libs folder, and the associated source .jar and doc .jar files in separate subfolders such as libs/src and libs/docs. You can use a name other than src and docs if you want, but it's important that the .jar files aren't directly in the libs folder.
Create a .properties file in the libs folder with the exact name of the actual library .jar (see example). Make sure you keep the .jar part.
Specify the relative paths to the sources and javadoc .jar in the .properties file.
Close and re-open the Eclipse project! Optionally, refresh the project by pressing F5.
Select an object of the linked library in the source code.
Open the Javadoc view in Eclipse to check the documentation (see screenshot).
Open the source code declaration (default shortcut: F3) of the selected object.
Example
The example uses the Gson library.
Directory structure of the libs folder:
libs
├── docs
│ └── gson-2.2.2-javadoc.jar
├── gson-2.2.2.jar
├── gson-2.2.2.jar.properties
└── src
└── gson-2.2.2-sources.jar
Contents of gson-2.2.2.jar.properties
src=src/gson-2.2.2-sources.jar
doc=docs/gson-2.2.2-javadoc.jar
Additional information
You can of course move the javadoc and sources .jar into other folders and specify relative paths. That's up to you. Placing the source and javadoc jars directly into the lib folder is possible but not recommended, as that causes documentation and source code to be included in your application.
Screenshot of the Eclipse JavaDoc panel:
Screenshot of an Eclipse project using Gson with Android 4.2.2.:
Referencing unpacked javadocs
In case you want to reference javadocs which are not provided as a packed .jar but simply as files and folders as asked by android developer in the comments do the following:
Place the library .jar in the libs/ folder
Create a yourlibraryname.jar.properties file (don't forget the .jar) with the following content:
doc=docs
Add the javadocs folders to the libs/ folder.
You should come up with the following folder structure:
├── docs
│ ├── allclasses-frame.html
│ ├── allclasses-noframe.html
│ ├── com
│ │ └── google
│ │ └── ads
│ │ ├── Ad.html
│ │ │ ....
│ │ └── package-tree.html
│ │ ...
│ └── stylesheet.css
├── GoogleAdMobAdsSdk-6.4.1.jar
└── GoogleAdMobAdsSdk-6.4.1.jar.properties
Do not forget to close and re-open the Eclipse project as mentioned above!
Here is a screenshot of a working example project referencing the GoogleAdMobAds Android library.
On windows you have to escape the backslash for references to doc and src paths in the properties file. Example, for
android-support-v4.jar the properties file content is something like:
doc=C:\\Program Files (x86)\\Android\\android-sdk\\extras\\android\\support\\v4\\docs
src=C:\\Program Files (x86)\\Android\\android-sdk\\extras\\android\\support\\v4\\src
An answer come from http://code.google.com/p/android/issues/detail?id=27490#c21
In your libs folder, you must have:
doc(folder)
foo_doc(folder)
index.html
...
...
foo.jar
foo.jar.properties
And in your foo.jar.properties, just put doc=./doc/foo_doc
Maybe you will have to refresh your project, to clean it, to close it and to reopen it.
It works for me!
I tried all of the above and none of them worked for me. I figured out a method that will always work. Basically, the culprit is the way that the ADT treats the "libs" folder so I quit using the "libs" folder. Instead I created a "libraries" folder and used it.
You can do the following and it will always work - even if the ADT should change how it changes how it deals with the "libs" folder in the future:
Create a "libraries" folder.
Create a sub-folder under it for each library.
Put all of the files for each library in the appropriate folder (java jar file, source jar file, javadoc jar file, etc).
Add the java jar file for each project in the "Libraries" tab for the Java Build Path by clicking on the Add Jars... button to add the jar from the library sub-folder in the "libraries" folder.
Attach the source/javadocs to each project by opening the project in the "Libraries" tab, selecting the desired item, and clicking on the Edit... button to add the source/javadocs from the library sub-folder in the "libraries" folder.
Check the checkbox for each project in the "Order and Export" tab for the Java Build Path.
After verifying that all libraries have been moved delete the "libs" folder.
By following the above procedure your project will have folders that look like this:
Your Java Build Path will look something like this:
In Order and Export the libraries are ticked:
For now, move the library you want Javadoc to lib. Them add that library to the Build Path and add the Javadoc.
Check this comment in the android issues.
On ADT 22 I could not access Javadoc for both commons-io-2.4.jar and android-support-v4.jar
This is the way I fixed it:
Precondition: both libraries are listed under "Referenced Libraries".
Right click on commons-io-2.4.jar and select Properties. This window appears:
commons-io-2.4.jar is bundled with commons-io-2.4-javadoc.jar, so I specified the Javadoc in archive External file path.
I did the same thing for the support library: right click on android-support-v4.jar and select Properties. This screen appears:
This time I specied the path to the source directory.
The library reference to commons-io-2.0.1.jar was broken when I upgraded to SDK Tools and ADT revision 17.
To resolve the problem I used Project -> Properties - > Java Build Path and I selected the Libraries tab. I deleted any reference to commons-io-2.0.1.jar and then used Add Jar to re-add commons-io-2.0.1.jar to the project. Then I click the ‘>’ arrow next to the library name to expand the library reference and I used the edit buttons to set the Source attachment and the Javadoc location.
Sorry I can't post an image as I don't have enough rep (please...).
Seems to be a moving target but, after having collected bits and pieces from many places (including answers to this very question that helped but failed to describe all necessary details, or maybe the system had changed slightly in the meantime), this seems to be the solution, at least as of now (August 28, 2013).
Open up a folder for your javadocs somewhere not inside your project.
Put your javadocs there unzipped, each into its own folder.
Inside your lib folder, add an xxx.jar.properties file for each lib you want to associate a javadoc with.
In that properties file, refer to the folder you unzipped the appropriate javadoc into (on Windows, escape the backslashes):
doc=d:\\Android\\javadoc\\libGoogleAnalyticsServices
Close and reopen your project in Eclipse (refreshing is not enough). You should now see the tooltips when you hover over the appropriate classes.
Failing to observe any of these steps (not unzipping the javadoc, referencing a file instead of a folder, etc) seems to break it.
I know this question is rather old, but when I was facing the same problem yesterday and the solution posted above was way too annoying for me, I found out that one can easily add a source path definition to the .classpath file of the project. Eclipse will then adapt it and you're able to browse through the source.
classpath entry before:
<classpathentry kind="lib" path="[PATH_TO_MY_JAR]"/>
After adding the path to the source
<classpathentry kind="lib" path="[PATH_TO_MY_JAR]" sourcepath="[PATH_TO_MY_SOURCE_JAR]"/>
Hope this helps
just update the ADT plugin. That worked for me!!
Start Eclipse, then select Help > Install New Software.
Click Add, in the top-right corner.
In the Add Repository dialog that appears, enter "ADT Plugin" for the Name and the following URL for the Location:
https://dl-ssl.google.com/android/eclipse/
Note: The Android Developer Tools update site requires a secure connection. Make sure the update site URL you enter starts with HTTPS.
Click OK.
In the Available Software dialog, select the checkbox next to Developer Tools and click Next.
In the next window, you'll see a list of the tools to be downloaded. Click Next.
Read and accept the license agreements, then click Finish.
If you get a security warning saying that the authenticity or validity of the software can't be established, click OK.
When the installation completes, restart Eclipse
Hope that helps!
For any given jar, if you would like to see the Javadoc help on the tooltip while coding, do the following:
Right click your project > Properties > Java Build Path > Libraries Tab. Click the arrow next to your jar to expand.
Source attachment should point to the location of the actual jar (probably right in your java folder).
Javadoc location: You have two choices here: URL and archive. If your javadocs for this jar are in the form of a folder containing an index.html file at the first level, choose 'Javadoc URL' and point to that folder.
If your javadocs are in a jar, choose 'Javadoc in archive' and point to the jar.
Don't forget to restart your workspace/close and reopen your project to update the tooltip with the Javadoc info.
I hope this helps give a simple answer for what I believe should be a very simple task.
My solution:
Download an eclipse plugin called: "Java Source Attacher Feature".
Later, select a jar and attach the source code using this plugin. Click in the jar file to select it, right buttom on the mouse, and then select "attach java source".
When you have the source code you have automatically the javadoc.
Now you can use F2 over the classes to view the asociated javadoc.
Enjoy
Related
Android Studio has changed its project structure yet again... now it is
project
└── app-module
├── manifests
├── res
└── java
I've been looking everywhere online, but I can't find where to put the assets folder. When I try to create the folder via the directory viewer in Android Studio (right-click, New... directory) the "directory" option is not available. The only available options are:
Java Class
File
Module
Package
Image Asset
None of which will do what I want here.
Has anyone figured this out?
An image of how to in Android Studio 1.5.1.
Within the "Android" project (see the drop-down in the topleft of my image), Right-click on the app...
You can click on the Project window, press Alt-Insert, and select Folder->Assets Folder. Android Studio will add it automatically to the correct location.
You are most likely looking at your Project with the new(ish) "Android View". Note that this is a view and not the actual folder structure on disk (which hasn't changed since the introduction of Gradle as the new build tool). You can switch to the old "Project View" by clicking on the word "Android" at the top of the Project window and selecting "Project".
According to new Gradle based build system. We have to put assets under main folder.
Or simply right click on your project and create it like
File > New > folder > assets Folder
To specify any additional asset folder I've used this with my Gradle. This adds moreAssets, a folder in the project root, to the assets.
android {
sourceSets {
main.assets.srcDirs += '../moreAssets'
}
}
right click on app-->select
New-->Select Folder-->then click on Assets Folder
I have a working app and now wish to include an advertising system by mopub. Looking at their getting started guide it says I should fist extract a "library project" (I'm not even sure what that is) using git. After having done that I now see that I have a directory called mopub-android-sdk inside this directory are a tree of further files and subdirectories.
The guide then states "Make sure the Android SDK files are in the same parent folder as your project"... this is where I'm confused. I have all my source files, androidmanifest etc in a directory c:\android\mygame am I now supposed to put mopub-android-sdk and all its sub-tree inside c:\android? or inside c:\android\mygame? (or somewhere else?)
EDIT: Some answers/comments have discussed the idea of converting the library project into a .jar file and then putting that in my libs directory... I have no objection to this so long as someone tells me there are no disadvantages to this compared to not making a jar - thinking about it more, wouldn't the jar have to include every single function, whereas if I left it as a library project, the compiler may be able to omit unused code?
EDIT: Now I am getting more sceptical about the make-jar-then-put-in-libs approach. I found mopub-android-sdk.jar in the bin\res directory and copied it to my projects libs directory. The ad system seemed to work fine, except in the location on screen where I expect to see a specific icon (to dismiss the full screen ad) there is a junk image. I noticed that amongst the tree of files beneath mopub-android-sdk there is a res directory containing png files. I suspect that these images are not in the jar file.
If you're simply including a *.jar library, put it in the libs/ folder of your project.
If you're trying to include an entire project...
Right click the project you want it to be included into and go to properties. On the left side where there are tabs, select "Android". In the area that says "Library" press the "Add..." button and then select the project you want to include. Do a clean build of your project.
Download the library to your host development system.
Create a new folder, libs, in your Eclipse/Android project.
Right-click libs and choose Import -> General -> File System, then Next, Browse in the filesystem to find the library's parent directory (i.e.: where you downloaded it to).
Click OK, then click the directory name (not the checkbox) in the left pane, then check the relevant JAR in the right pane. This puts the library into your project (physically).
Right-click on your project, choose Build Path -> Configure Build Path, then click the Libraries tab, then Add JARs..., navigate to your new JAR in the libs directory and add it. (This, incidentally, is the moment at which your new JAR is converted for use on Android.)
I am trying to compile a java project which makes uses of android libraries. The project I am using is checked out from a svn repository.
In order to take a use of that project I am required to define some jar files and libraries for that project.
Here are the files that I need to make sure they are defined:
•"lib/apache-mime4j-0.4.jar" : Jar
•"lib/httpmime-4.0-beta1.jar" : Jar
•"lib/slf4j-android-1.5.8.jar" : Jar
•"JUnit 4.libraryclasspath" : Library
•"ANDROID_SDK_PLATFORM/android.jar" : var
•"Java JRE System Library" : Library
Does anyone have any idea about what should I do to define these files? I am a noob here.I do not know which selection should I choose When I clicked "project -> properties -> java build path -> libraries"
For example if I want to define the first jar file, there are a "add external jar" and a "add libraries" selections.
However you can see a "lib" here in front of the "apache-mime4j0.4.jar file" in this list above..
So I don't understand if it is asking me to add a jar file or the librabry.. I am getting very confused about this.
And also How can I do anything with "JUnit 4.libraryclasspath" file? I think it is a classpath file so I cannot either choose "add jar files" or "add libraries" to define it..
Hope someone has any knowledge about this and I will be very appreciated!
I think You are unable to include the files due to SVN path but will discuss it later.At first we look how to add jar files
Right click on your project in which you want to add the jars
1.select build path and then "configure build path"
2.click on "Libraries" tab
3.Now click on Add external jars (as your all jars files would be placed in some directory outside the project folder or anywhere else)
4.Select these jars and now do OK ... Now these jars are in your class path and you can use these files.
Now another thing, As You told that you are using svn , It means many of other developers are also using the same project then it is compulsory that all of you have same path of jars in your systems for instance in Dev1 PC the jar if the jar file is placed in d:/lib/jars folder then all other DEV2 , DEV3 ... DEVn must have d:/lib/jars folder and their jars must be placed there and you have to add these jars from d:/libs/jars
Last thing , If you are still unable to understand the solution and remove the bugs then simply do this.
Copy all jar files manually (ctrl+c) and copy to lib folder in your project as i have seen that in your project the person who commits the code place them there.
after then , right click on your project and click refresh(as it is bad practice to put jar files in project by creating folder like lib etc unless it is a web project)
Let me know if anything is unclear about this
I'm working on an Android project and i need to import an XML library called XOM. The only way i found was to right click on the project name -> Properties -> Libraries tab -> click on "Add external Jar". But that only references it from it's original path, what happens when i compile the app and move it to my phone? Will the Jar be in there?
Might be a stupid question, sorry if that's the case.
It's fine to do that but what I normally do is create a folder called liband then add Jars from there. I find that makes it easier to see what Jars I have in my application.
The main disadvantage of your original approach is that what if the path to that library externally accidentally changes? then your program will not compile. It's better to have everything in the one place to make things easier.
.apk is nothing but a collection or zipped version of a file. it contains all the resources and compiled java files.
So you need not have to worry about the inclusion of your library files. if you have set proper path to your libraries in eclipse then these will be included in your apk file.
Create a directory called "libs" in your under your root directory. You can do it by,
Right click on the project which is in the Package Explorer window in
Eclipse.
New -> Folder -> give "libs" as the Folder name
Copy your jar file and paste it to in the "libs" folder
Expand the "libs" folder
Right click on your copied jar file -> Build Path -> Add to build
path
That's it
I am going to create a library project which has several dependencies (jar files).
I am confused because I've seen some android projects which has LIB or LIBS folder under project root folder (together with bin,gen,res,src.etc..)
Even I add LIB or LIBS folder, then put the jar files on it. Still need to set the project properties in order to recognize the added jar files by doing Project Properties => Java Build Path => Libraries tab => Add JARs... button.
I am using Eclipse with Android Plugin.
When I add LIBS, it will appear the Android logo on the top of the LIBS folder. It is recognized by the plugin but still need to set it in the project properties (same the above adding JARs)
Which is the correct directory structure for Android Project?
If you use the Android command line to create your project, it'll default to libs/. It turns out that the Android Ant tasks are set to look in libs/ by default.
See $ANDROID_HOME/tools/ant/main_rules.xml:
<property name="jar.libs.dir" value="libs" />
If you just care about Eclipse, you can use whatever you want.
In newer revisions of ADT (revision 17 onwards), the Ant-based build system and the Eclipse plug-in are aligned so that they behave the same way. This means, by default, only the jars that are present in the libs folder are included in the final apk file. These jars would automatically appear under "Android Dependencies" in your Eclipse project.
For more details please refer here. http://tools.android.com/recent/dealingwithdependenciesinandroidprojects
It doesn't matter actually. It can be lib or libs. Whether jar files are in lib or in libs, you just need to do right click on project, select "Build path => Add to build path" , thats it.
Citing: http://tools.android.com/recent/dealingwithdependenciesinandroidprojects
If you are still referencing jar libraries manually instead of putting them under libs/ be aware of the following:
If the project is a Library project, these jar libraries will not be automatically visible to application projects. You should really move these to libs/
If the project is an application, this can work but you must make sure to mark the jar files as exported.