Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create jar for android project in eclipse

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>
like image 684
unkown Avatar asked Jul 02 '12 06:07

unkown


People also ask

How do I create a .JAR file?

Open the Jar File wizard In the Package Explorer select the items that you want to export. If you want to export all the classes and resources in the project just select the project. Click on the File menu and select Export. In the filter text box of the first page of the export wizard type in JAR.

Does JAR work on Android?

Your Android device can run Java games and apps, but it isn't designed to do so, and hence you don't find any Java emulators on the Play Store to run jar files on Android devices.

What is a JAR file in Android?

A JAR (Java Archive) is a package file format typically used to aggregate many Java class files and associated metadata and resources (text, images, etc.) into one file to distribute application software or libraries on the Java platform.


2 Answers

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

like image 103
YuDroid Avatar answered Sep 29 '22 00:09

YuDroid


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

like image 26
CSharp Avatar answered Sep 28 '22 22:09

CSharp