Create jar for android project in eclipse

25,934

Solution 1

In Eclipse, select project, right click on the project, Select Export, From that select Jar. Then follow the simple wizard and give the destination where you want to save your jar, and finish. You can find your jar there. enter image description here

Solution 2

Step 1. Create Android library project as explained here.

Step 2. Now you need to give reference of Android Library project created in step 1 to your client application. There are two ways to do so.

•Give reference of Android Library Project itself by client app property -> Select 'Android' on left pane -> In Libraty Section, Add Android Libraty project (This is explained at link given in Step 1 above)

•Give the reference of .jar file of Android Library project (from Location of Android Library project -> bin -> .jar file). Client Application -> Properties -> Click 'Java Build Path' in lefe pane -> Go to 'Libraries' Tab -> Click 'Add External JARs' button and select the .jar file -> Go to 'Order and Export' tab and select the added .jar file reference and move it to top.

Hope this will help you

Share:
25,934
unkown
Author by

unkown

Updated on April 09, 2020

Comments

  • unkown
    unkown about 4 years

    Hello all how can I create jar file of my project that is created in android using eclipse. I have done in this way project -> right-click->export --> select builder -->antbuilder-->ok then after this process build.xml will be created. On bulid.xml I will create new builder.

    • Right click on project -> properties --> select new -->give build.xml and your project path and press ok, new builder will be created.
    • Now select that builder from project properties and press ok.
    • Now build your project and your jar will be created in bin folder.

    I have followed above process but my jar is not found in bin folder. I can see my build.xml is created and all process goes smooth but still jar is not created. Can any one tell me how can I do this?

    My build.xml

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <!-- WARNING: Eclipse auto-generated file.
                  Any modifications will be overwritten.
                  To include a user specific buildfile here, simply create one in the same
                  directory with the processing instruction <?eclipse.ant.import?>
                  as the first entry and export the buildfile again. -->
    <project basedir="." default="build" name="testtttttttttt">
        <property environment="env"/>
        <property name="debuglevel" value="source,lines,vars"/>
        <property name="target" value="1.6"/>
        <property name="source" value="1.6"/>
        <path id="Android 2.2.libraryclasspath">
            <pathelement location="C:/Program Files (x86)/Android/android-sdk/platforms/android-8/android.jar"/>
        </path>
        <path id="com.android.ide.eclipse.adt.LIBRARIES.libraryclasspath"/>
        <path id="testtttttttttt.classpath">
            <pathelement location="bin/classes"/>
            <path refid="Android 2.2.libraryclasspath"/>
            <path refid="com.android.ide.eclipse.adt.LIBRARIES.libraryclasspath"/>
        </path>
        <target name="init">
            <mkdir dir="bin/classes"/>
            <copy includeemptydirs="false" todir="bin/classes">
                <fileset dir="src">
                    <exclude name="**/*.java"/>
                </fileset>
            </copy>
            <copy includeemptydirs="false" todir="bin/classes">
                <fileset dir="gen">
                    <exclude name="**/*.java"/>
                </fileset>
            </copy>
        </target>
        <target name="clean">
            <delete dir="bin/classes"/>
        </target>
        <target depends="clean" name="cleanall"/>
        <target depends="build-subprojects,build-project" name="build"/>
        <target name="build-subprojects"/>
        <target depends="init" name="build-project">
            <echo message="${ant.project.name}: ${ant.file}"/>
            <javac debug="true" debuglevel="${debuglevel}" destdir="bin/classes" source="${source}" target="${target}">
                <src path="src"/>
                <classpath refid="testtttttttttt.classpath"/>
            </javac>
            <javac debug="true" debuglevel="${debuglevel}" destdir="bin/classes" source="${source}" target="${target}">
                <src path="gen"/>
                <classpath refid="testtttttttttt.classpath"/>
            </javac>
        </target>
        <target description="Build all projects which reference this project. Useful to propagate changes." name="build-refprojects"/>
        <target description="copy Eclipse compiler jars to ant lib directory" name="init-eclipse-compiler">
            <copy todir="${ant.library.dir}">
                <fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
            </copy>
            <unzip dest="${ant.library.dir}">
                <patternset includes="jdtCompilerAdapter.jar"/>
                <fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
            </unzip>
        </target>
        <target description="compile project with Eclipse compiler" name="build-eclipse-compiler">
            <property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/>
            <antcall target="build"/>
        </target>
    </project>