Create External Jar Files - android

I have created a library project which can be used as reference project in any application.
Now i want to create jar file of that library project so that instead of referencing the library project,i can add that created external jar file to build path and can use the library project component.Is there any way in eclipse to do so???

JAR file using Eclipse IDE
Creating JAR file using Eclipse IDE is pretty much easy. Follow the simple steps.
Right click on your project, which you want to create a JAR file of. And select Export from the context menu.
Select JAR file from Java folder and click Next.
Provide the Destination path and click on Finish to create the JAR.
Here how to add JAR to your project, you can also create libs folder and drag an drop your jar inside this folder

You will need to export that project in eclipse. here are the steps:
1) right click the project in project explorer view.
2) click on exprot and type jar.
3) select the jar option and by giving appropriate name click on export.
The jar file will be created which u can use by adding it in the build path of another project.

yes, You can do it in Eclipse...
//Exporting project to jar file
Right Click the desired project->Export the project->Choose java->jarFile->Select the project to the export and choose the destination for the jar file to be saved->Click finish-> jar file will be created in desired destination
//Including jar file
Again Right Click the project(where jar file to be included)->Choose Properties->Select the java build path->add External jar->choose the jar file->jar file will be included.

Related

Convert android library project to jar file with resources (libs and build folder)

I make an android library project. It has some jar files and .so files.
I export this project as jar file
File->export->jar file->check my project with all folders and files,
uncheck AndroidManifest.xml,
check Export all output folders for check project
check Export java source files and resources
-> finish.
But when I add to my another project(libs folder) and add this on javaBuildPath, after run in the log cat show "NoClassDefFound Error (one of the jar file)".
How can I fix this problem?
Edit: I'm using Eclipse IDE
Please follow the steps:
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
Must clean and build.

Attachment of a .jar file to eclipse

I am new to Android.I have a source code (i.e., jar file) of an app in my PC.How can i get those files into the eclipse i.e., how to open those source code files so as to run them on AVD?
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.
For more info see this link Adding an External Library (.jar) using Eclipse
Or More simply
A good way to add external JARs to your Android project or any Java project is:
Create a folder called libs in your project's root folder
Copy your JAR files to the libs folder
Now right click on the Jar file and then select Build Path > Add to
Build Path, which will create a folder called 'Referenced Libraries'
within your project
Edit
And if you want to see also the .jar classes content then see this link How to decompile a whole Jar file?
Convert the .jar to .dex with jar2dex and execute the .Dex for android runs dalvik code but can't run .jar

Android- how to Convert library project to external jar files

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.

how to define jar files and libraries in eclipse indigo?

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

NoClassDefFoundError when project imported to Eclipse?

I am working on an app which uses Commonslang.jar libraries. I was trying to setup it on a new system with newly installed Eclipse.The project is not showing any error But when I run the project it force closes with NoClassDefFoundError at each point where I use Commonslang lib.
I dont know how to fix this problem.Please help?
I think there are "lib" folder in your project directory so just change it "libs" instead of "lib" and clean project and check it..
> Note: No need to build path for any third party library
You need to create libs folder in your project and copy that jar file there. Then in eclipse, right-click on that jar file (which is in libs folder) select Build Path and then select Add to Build Path.
Remember: if you are using a jar file in your Android Library Project, and associating that library project with your regular UI
project, it won't be enough. You must need to include that jar file
(as described above) in both of your projects (Android Library and UI
project) to make it work.
Have you added the jar to the Java Build Path?
Go to the Properties for the Project and select Java Build Path -> Libraries tab then add the external jar there.

Categories

Resources