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
Related
I initially thought it was exclusively for official libraries like the support library. However any time I add a custom JAR using the "Add to build path" menu item, it automatically shows up in both "Referenced Libraries" and "Android Private Libraries". One of these is redundant since there is no point in exporting both at build time. Additionally, "Android Private Libraries" cannot be modified so I can't (easily) add java doc or source paths. Not to mention it just seems wrong that a custom JAR is in "Android Private Libraries".
I cannot delete the entry from "Android Private Libraries" to use only "Referenced Libraries" either.
In my case i always add libraries to libs folder.
According to my understanding thats the way its suppose to be. Android Private Library folder references these jars in libs folder. The Android Private Library is used during the creation of apk (probably during the conversion of your java code into dex file).
I don't have any problem with custom jars. They are only in Reference Libraries in my case. I suggest you to look at Order and Export tab in java build path properties.Just check all the custom jars and uncheck all the Android specific libraries. If you want all jars in Reference Libraries then check all jars and clean your project.
you just need to put jar and jardoc to a folder but not the folder "libs".
Then there will be a 'Reference Library',
Then you can add jardoc to jar by properties of jar in Reference Library.
1: New a Folder named sth but not "libs"
like folder named 'lib'.
2: Put your .jar and .jardoc in the new folder
the folder 'lib' in this tutorial
3: Add the jar and jardoc to project.
Then, a 'Reference Libraries' will appear
4: Delete original jar/jardoc.jar in libs (if you've imported them to libs before).
5: add XXXjavadoc.jar to XXX.jar as doc location.
The title might seem confusing (although accurate). Let me explain it in more words:
I have an android Library project, lets call it ProjectA. I also have second android Library project, lets call it ProjectB. The ProjectB and ProjectA are in the same workspace, and ProjectB is referencing ProjectA in it's libraries list (project properties). So ProjectB is using ProjectA.
Now what I want to accomplish is to get a simple jar of the library - ProjectB, and include this jar as external library in my yet another android project (android application this time).
However... when I compile ProjectB, the jar size is way too small (the ProjectA's jar is over 300KB, yet ProjectB's jar is only 14KB), so I'm sure it does not contain ProjectA's in the jar file I find inside bin folder (of the ProjectA). To do a quick math, ProjectB's jar should be ~300KB bigger.
So to repeat, I'd like to have everything the library needs, packed in one jar file (jar file of ProjectB's), so that when I import it into libs of an Android Application I can use it.
Any help here from expierienced Android dev?
If you are searching for the quickest way to do this, in Eclipse highlight your library project, then go to File > Export and under Java select JAR. From there, you can select a multitude of options, including which other referenced projects should be exported as part of the JAR.
Commonsware is correct, it's just a JAR, there is no magic. If you need a build system option then consider using Ant or Gradle to package the JAR for you. Do not however, try to use what is in the bin folder, as that is not meant for you to use.
You need to make sure you export the library in your Build Path. For Eclipse, you can Right-click on the project, choose "Build Path" > "Configure Build Path", go to the "Order and Export" tab on the right side, and make sure that your library is checked in the list there (it might be contained in one of several library groups if your Project has multiple dependencies).
i have a requirement like i have to use one app for two other applications. so i want to create a library project as jar file so that i can use that in build path easily with out adding the project. so i have added my main project as a library project so it has generated jar file in bin folder . so i have copied that jar file and added to libs and added that to my project build path. but still i am getting no class def found exception. please sugest whether this process of generating a jar file is correct or not. if it is not correct please suggest me how to do.
Rightclick on the library project, export -> Jar file.
Select all files, except the AndroidManifest.xml.
Make sure you DON'T select manifest file. Else it will lead to conflict errors.
Now include this JAR file in the build path, and it will work. I did the same.
Let me know if you have any issues.
The Most Important thing , your project doesn't contain any Resources (RES folder) then
1- Right Click on Project –> Export —> Java –> JarFile
2-Select only the src checkbox ie the (pacakages) in Top-Left Window.
Don’t Select anything in Top-Right Window if some thing is selected remove marks .
3-Select Only Export generates Class Files and Resources
4-In Options Select only Compress the contents of the jar file (it's not important)
To add your External Jar to Your File
1-Right click on project –> Select Properties –> Java Build Path —> libraries –> Add External Jar Files –> Click OK
2-CLEAN your Project
You can export your project as a jar.To do this
right click your project->export->java->JAR file->Next
But if you use resources in the library project then you won't get it from the jar.But it will be available if you use as a library project rather than jar
You cannot export a library project to a JAR file
A library cannot be distributed as a binary file (such as a JAR file). This will be added in a future version of the SDK Tools.
Source
You need to do following:
Add reference of .jar file to your client application. Right click project -> properties -> Click 'Java Build Path' -> open Libraries tab -> Click button 'Add External JARs..' and select the .Jar file that you have created -> Go to 'Order and Export' tab and select the Added external Jar and move it to the top.
I hope this will help you.
Mark +1 if it is helpful to you.
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.