【问题标题】:Create jar for android project in eclipse在eclipse中为android项目创建jar
【发布时间】:2012-07-02 13:39:40
【问题描述】:

大家好,我如何创建使用 Eclipse 在 android 中创建的项目的 jar 文件。我已经这样做了 project -> right-click->export --> select builder -->antbuilder-->ok 然后在这个过程之后 build.xml 将被创建。在 bulid.xml 上,我将创建新的构建器。

  • 右击项目->属性-->选择新建-->给出build.xml和你的项目路径,然后点击确定,新的构建器将被创建。
  • 现在从项目属性中选择该构建器,然后按确定。
  • 现在构建您的项目,您的 jar 将在 bin 文件夹中创建。

我已按照上述流程进行操作,但在 bin 文件夹中找不到我的 jar。我可以看到我的 build.xml 已创建并且所有过程都很顺利,但仍然没有创建 jar。谁能告诉我该怎么做?

我的 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>

【问题讨论】:

  • Android可执行文件是.apk文件,为什么需要jar文件?
  • 你能在这里添加你的 build.xml 吗?

标签: java android eclipse jar


【解决方案1】:

在 Eclipse 中,选择项目,右键单击项目,选择导出,从该项目中选择 Jar。然后按照简单的向导,给出你想要保存 jar 的目的地,然后完成。你可以在那里找到你的罐子。

【讨论】:

  • @lenda : 很高兴随时为您提供帮助.. :)
  • 另一种选择。如果您将您的项目标记为库项目,则会自动生成一个 jar 文件。右键单击项目选择属性,然后从左侧选择Android,然后通过选中“Is Library”您可以将您的项目作为库项目。然后检查 bin 文件夹。如果 jar 不存在,请清理并构建项目。
  • 有没有办法在那个 jar 中导出依赖项(jar)?
  • 这对我不起作用,如果我在我的 Android 应用程序中将它用作库项目,我想导出为 .jar 文件的库运行良好,但是当我将它导出为 .jar 时,我收到警告,.jar 没有按预期工作
【解决方案2】:

第 1 步。按照here 的说明创建 Android 库项目。

第 2 步。现在您需要将第 1 步中创建的 Android 库项目的引用提供给您的客户端应用程序。有两种方法可以做到这一点。

•通过客户端应用程序提供 Android Library Project 本身的参考 属性 -> 在左侧窗格中选择“Android” -> 在库部分中,添加 Android Libraty 项目(这在第 1 步中给出的链接中进行了解释 以上)

•给出Android Library项目的.jar文件参考 (从 Android 库项目的位置 -> bin -> .jar 文件)。 客户端应用程序 -> 属性 -> 单击 lefe 中的“Java 构建路径” 窗格->转到“库”选项卡->单击“添加外部JAR”按钮并 选择 .jar 文件 -> 转到“订购和导出”选项卡并选择 添加 .jar 文件引用并将其移至顶部。

希望对你有帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-11-26
    • 1970-01-01
    • 2014-08-28
    • 2013-06-08
    • 1970-01-01
    • 1970-01-01
    • 2012-11-01
    相关资源
    最近更新 更多