4

Android プロジェクトと ant プロジェクトに外部 jar を追加することについてかなりの数の質問があるようですが、このインスタンスで機能する解決策を見つけていません。私は Ant にあまり詳しくないので、おそらく問題を悪化させます。

問題は: JSch ライブラリを uiautomator プロジェクトに追加しようとしています。「android create uitest-project」によって見つかることを期待して、jsch.jar ファイルを /libs フォルダーに入れました。ただし、そうではありません-したがって、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 はそのまま使用されます。

4

4 に答える 4

9

こんにちは、同じ問題に遭遇しました。次の手順に従って修正します。

  • 1 プロジェクトのダートリーに「libs」ダートリーを作成し、すべての外部 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 "Ant Build" として実行される "build.xml" を選択します。

  • 4 は tow jar ファイルを生成します。追加の jar ファイルの名前は「bundle.jar」です。

  • 5 /data/local/tmp/ に bundle.jar をプッシュします。

  • 6 adb シェル uiautomator xxxTestCast.jar バンダー.jar -c com.xxx.MainClass

できます!

于 2014-02-21T09:22:32.540 に答える
0

日食を使用している場合

プロジェクト エクスプローラーから、作成した新しいプロジェクトを右クリックし、[プロパティ] > [Java ビルド パス] を選択して、次の手順を実行します。 [外部 JAR の追加...] をクリックし、ディレクトリに移動して jar ファイルを追加します。

于 2013-10-14T04:39:03.563 に答える