2013-04-15 83 views
4

似乎有關於將外部罐子添加到android項目和螞蟻項目的相當多的問題,但我沒有找到適用於此實例的解決方案。我對Ant不太熟悉,可能會激怒這個問題。將外部罐子添加到Android UIautomator項目

問題是:我試圖將JSch庫添加到我的uiautomator項目中。我把jsch.jar文件放到/ libs文件夾中,希望它能被'android create uitest-project'找到。然而,情況並非如此 - 這樣看來我需要修改的build.xml/ant.properties/build.properties或東西讓螞蟻找到罐子

特定的錯誤是:

[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 

構建.xml是由android腳本創建的,而Ant是開箱即用的 - 所以我認爲我的螞蟻知識是問題:P。

+0

對不起,我專注於運行時的方面,所以我擺脫了我的答案(以幫助鼓勵其他答案)。在Eclipse中,您可以將它作爲外部JAR添加到構建路徑中。如果Ant沒有拿起'libs /'...我不知道如何解決這個問題。如果你在這裏沒有愛,試試'adt-dev'谷歌組 - 這可能只是Ant腳本方面的一個缺失功能​​。 – CommonsWare

+0

@CommonsWare感謝您的更新!你鼓勵我深入研究ant構建腳本。儘管我仍然不知道要做什麼,但似乎將導入到build.xml中的uitest.xml在實際構建過程中不包含任何外部jar文件 - 儘管參考ID在那裏。這感覺有點像他們從其他部分複製粘貼,並從編譯中刪除外部庫。這大多是猜測。 我只需要弄清楚如何將它們添加回來,如果是這樣的話:S – Brian

+0

對此有何更新?我似乎偶然發現了同樣的問題。 – aragaer

回答

0

,如果你使用eclipse

從Project Explorer中,您創建的新項目上單擊右鍵,然後選擇屬性> Java構建路徑,並執行以下操作: 點擊添加外部JAR ...並導航到該目錄並添加jar文件

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> 
8

您好我滿足相同的問題;解決呢遵循以下步驟:

  • 1創建項目dirtory 「庫」 dirtory,放在庫dirtory所有extrnal jar文件。
  • 2在具有以下內容的項目dirtory中添加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構建」 每一個是確定的。

  • 4將產生絲束jar文件,額外的jar文件被命名爲在/數據/本地的/ tmp/

  • 6 ADB殼uiautomator 「bundle.jar」

  • 5推bundle.jar xxxTestCast.jar bunder.jar -c com.xxx。MainClass

它的工作原理!

+0

謝謝!這段代碼解決了我的問題。 :d – thiagolsilva

相關問題