关于将外部jar添加到android项目和ant项目中似乎有相当多的问题,但我找不到在这种情况下有效的解决方案。 我对Ant不太熟悉,这可能会激怒这个问题。

问题是:我正在尝试将JSch库添加到我的uiautomator项目中。 我将jsch.jar文件放入/ libs文件夹中,希望它可以通过'android create uitest-project'找到。 然而,事实并非如此 - 所以我似乎需要修改build.xml / ant.properties / build.properties或者其他什么来获取ant来查找jar

具体错误是:

[javac] Compiling 5 source files to /Users/.../KeyEvents/bin/classes
[javac] /Users/.../KeyEvents/src/com/proj/automation/core/coreSSH.java:9: error: package com.jcraft.jsch does not exist

build.xml是由android脚本创建的,Ant是开箱即用的 - 所以我认为我的蚂蚁知识是问题:P。

===============>>#1 票数:9

嗨,我遇到了同样的问题。我修复它按照以下步骤:

  • 1在项目中创建“libs”的脏东西,将所有extrnal jar文件放在libs中。
  • 2在项目内容中添加一个custom_rules.xml文件,其中包含以下内容。

https://github.com/xiaocong/android-uiautomator-jsonrpcserver/blob/master/custom_rules.xml

<!-- Include external libs -->
<property name="jar.libs.dir" value="libs" />
<property name="jar.libs.absolute.dir" location="${jar.libs.dir}" />
<path id="classpath">
    <fileset dir="${jar.libs.absolute.dir}">
        <include name="**/*.jar"/>
    </fileset>
</path>

<property name="dex.file.name" value="classes.dex" />
<property name="out.dir" value="bin" />
<property name="out.absolute.dir" location="${out.dir}" />
<property name="out.absolute.bundle.dir" location="${out.absolute.dir}/bundle" />
<property name="intermediate.dex.bundle.file" location="${out.absolute.bundle.dir}/${dex.file.name}" />

<property name="out.bundle.file" value="${out.absolute.dir}/bundle.jar" />

<target name="-pre-compile">
    <mkdir dir="${out.absolute.bundle.dir}" />
</target>

<!-- overwrite the compile target in uibuild.xml to include to external jars -->
<target name="compile" depends="-build-setup, -pre-compile">
    <javac encoding="${java.encoding}"
            source="${java.source}" target="${java.target}"
            debug="true" extdirs="" includeantruntime="false"
            destdir="${out.classes.absolute.dir}"
            bootclasspathref="project.target.class.path"
            verbose="${verbose}"
            fork="${need.javac.fork}">
        <src path="${source.absolute.dir}" />
        <classpath refid="classpath"/>
        <compilerarg line="${java.compilerargs}" />
    </javac>
</target>

<!-- empty default post-dex target. Create a similar target in
     your build.xml and it'll be called instead of this one. -->
<target name="-post-dex">
    <dex executable="${dx}"
            output="${intermediate.dex.bundle.file}"
            nolocals="@{nolocals}"
            verbose="${verbose}">
        <fileset dir="${jar.libs.absolute.dir}">
             <include name="**/*.jar"/>
        </fileset>
    </dex>
</target>

<!-- empty default post-jar target. Create a similar target in
     your build.xml and it'll be called instead of this one. -->
<target name="-post-jar">
    <jar destfile="${out.bundle.file}">
        <fileset file="${intermediate.dex.bundle.file}" />
    </jar>
</target>

<target name="install" description="Install the test package">
     <exec executable="${adb}" failonerror="true">
        <arg line="${adb.device.arg}" />
        <arg value="push" />
        <arg value="${out.file}" />
        <arg value="/data/local/tmp" />
    </exec>
     <exec executable="${adb}" failonerror="true">
        <arg line="${adb.device.arg}" />
        <arg value="push" />
        <arg value="${out.bundle.file}" />
        <arg value="/data/local/tmp" />
    </exec>
</target>

  • 3选择“build.xml”作为“Ant Build”运行,每个都可以。

  • 4将生成两个jar文件,额外的jar文件名为“bundle.jar”

  • 5在/ data / local / tmp /中推送bundle.jar

  • 6 adb shell uiautomator xxxTestCast.jar bunder.jar -c com.xxx.MainClass

有用!

===============>>#2 票数:2

看看这里[1]。 只需复制此文件并将所需的jar放在目录库中,因此运行ant build,ant install和finally ::

adb shell uiautomator runtest YourTest.jar bundle.jar -c your.test

[1] - https://github.com/xiaocong/android-uiautomator-jsonrpcserver/blob/master/custom_rules.xml

===============>>#3 票数:2

在项目中创建lib目录保留所有必需的jar然后创建新的custom_rule.xml并复制下面编写的代码,然后它将工作文件或者您也可以将此代码粘贴到build.xml的最后。

<property name="jar.libs.dir" value="libs" />
<property name="jar.libs.absolute.dir" location="${jar.libs.dir}" />
<path id="classpath">
    <fileset dir="${jar.libs.absolute.dir}">
        <include name="your-helping-version.jar" />
        <include name="gson-2.2.2.jar" />
    </fileset>
</path>

<!-- version-tag: VERSION_TAG -->
<import file="${sdk.dir}/tools/ant/uibuild.xml" />


<!-- overwrite the compile target in uibuild.xml to include to external 
    jars -->
<target name="compile" depends="-build-setup, -pre-compile">
    <javac encoding="${java.encoding}" source="${java.source}"
        target="${java.target}" debug="true" extdirs="" includeantruntime="false"
        destdir="${out.classes.absolute.dir}" bootclasspathref="project.target.class.path"
        verbose="${verbose}" fork="${need.javac.fork}">
        <src path="${source.absolute.dir}" />
        <classpath refid="classpath" />
        <compilerarg line="${java.compilerargs}" />
    </javac>
</target>

<!-- overwrite the -dex target in uibuild.xml to include external jar files 
    into the target dex file. -->
<target name="-dex" depends="compile, -post-compile">
    <dex executable="${dx}" output="${intermediate.dex.file}"
        nolocals="@{nolocals}" verbose="${verbose}">
        <fileset dir="${jar.libs.absolute.dir}">
            <include name="your-helping-version.jar" />
            <include name="gson-2.2.2.jar" /> 
        </fileset>
        <path path="${out.classes.absolute.dir}" />
    </dex>
</target>

===============>>#4 票数:0

如果你正在使用eclipse

在Project Explorer中,右键单击您创建的新项目,然后选择Properties> Java Build Path,并执行以下操作:单击Add External JARs ...并导航到该目录并添加jar文件

  ask by Brian translate from so

未解决问题?本站智能推荐: