Objective : Create .jar file of an Android Library Project.
Description : This this blog we learn how to create .jar file of and Android Project. Assume we have two project one is Library project we want to convert it in library.jab and another is sample Android project we will add this jar into this project.
Creating Library Project :
Step #1 : Open a create new Android Project wizard and fill Application name, Project name and package name, then click on next. In next screen select make this project as library checkbox then click on finish.
Step #2 :
Add a package in Source folder
Step #3 :
Add a Class in package : In our case i have add MyLibToast Class in our com.library package.
Step #4 : MyLibToast.java
We have create one Method : for showing toast
@param context : Context of calling
@param message : The message want to show
public void showMyLibToast(Context context,String message){
Toast.makeText(context,message, Toast.LENGTH_SHORT).show();
}
Now our library has been finished.
Step #5 : Compiling Library
Android Project > Build Project ( Make sure project > Build Automatically not selected )
Library have completed.
Step 6 : Create a sample project
Step 7 : Add a Library in Sample Project.
Right click on project > Properties > Android > Add > Select Library Project form list.
Step #8 : Call a method of Library Project.
Create a object of : MyLibToast mMyLibToast;
Initializing Object mMyLibToast=new MyLibToast();
Calling of ShowMyLibToast Method :
mMyLibToast.showMyLibToast(Sample.this, "This is library call form sample");
Step #9 : Running Sample Project : Run > Run
Step #10 Convert Library Project To .jar
10.1 - Right Click on Library Project at Project Explorer > Select Export
10.2 - Below screen appear Select > Java > Jar > Next
10.3 - Add our Source file to Jar make sure only source file are included in jar no resource will added in jar then click on Finish.
10.4- : Now your Jar file is ready for shoring.
Step #11 : Now remove library project from Sample Project and add our library.jar
11.1 - Adding Jar to Project
Right Click on Sample Project > Properties > JavaBuild Path > Library > Add External Jar > Select library.jar form path.
Now library.jar is added in your project you can call showMyLibToast method form your Sample project.
As we call in Step #8 .
I hope this blog is help you for making .jar file of your library project.
Your can download Source Code of Library Project LibraryProject.zip
Your can download Source Code of Library Project LibraryProject.zip









