将外部Jar文件添加到Bash脚本中的ant构建中

时间:2015-01-15 02:01:24

标签: java bash ant

我已经回顾了许多与此相关的帖子,但似乎无法找到明确的解决方案。我试图使用emma为应用程序提供代码覆盖,并将robotium作为测试单元。外部dropbox.jar位于eclipse中的构建路径中。

应用程序和测试用例在Eclipse中成功运行,但是在运行脚本时,ant无法找到dropbox.jar依赖项。下面是我的脚本,后面是来自蚂蚁电话的日志部分

#!/bin/bash
#Code Coverage Script:
#(android:command not found error)
export ANDROID_HOME=/Users/Deverick/android-skds
export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
export PATH=$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools:/Users/Deverick/Documents/workspace/Diary-Test/libs/dropbox-android-sdk-1.6.1:$PATH

echo $PATH
cd ~/Documents/workspace/
cd Diary
ant clean
cd ..
cd Diary-Test
ant clean
cd ..
android  update project --path ./ --name Diary --target android-16 --subprojects
cd Diary-Test
android  update test-project --main ../Diary --path ./
ant emma debug install
ant emma debug install test

日志输出:

 -code-gen:
[mergemanifest] Merging AndroidManifest files into one.
[mergemanifest] Manifest merger disabled. Using project manifest only.
     [echo] Handling aidl files...
     [aidl] No AIDL files to compile.
     [echo] ----------
     [echo] Handling RenderScript files...
     [echo] ----------
     [echo] Handling Resources...
     [aapt] Generating resource IDs...
     [echo] ----------
     [echo] Handling BuildConfig class...
[buildconfig] Generating BuildConfig class.

-pre-compile:

-compile:
    [javac] Compiling 4 source files to /Users/Deverick/Documents/workspace/Diary/bin/classes
    [javac] /Users/Deverick/Documents/workspace/Diary/src/jpf/android/diary/Diary.java:2: warning: unmappable character for encoding UTF-8
    [javac] //  Copyright ? 2012  Josep Portella Florit <hola@josep-portella.com>
    [javac]               ^
    [javac] /Users/Deverick/Documents/workspace/Diary/src/jpf/android/diary/Diary.java:39: package com.dropbox.client2 does not exist
    [javac] import com.dropbox.client2.DropboxAPI;
    [javac]                           ^
    [javac] /Users/Deverick/Documents/workspace/Diary/src/jpf/android/diary/Diary.java:40: package com.dropbox.client2.android does not exist
    [javac] import com.dropbox.client2.android.AndroidAuthSession;

如何将此.jar路径添加到脚本中,以便将其视为依赖项?我看过一些对$ CLASSPATH的引用。引用此问题的大多数问题都使用build.xml文件来添加依赖项,但是脚本每次都会清除build.xml。非常感谢任何澄清!

2 个答案:

答案 0 :(得分:0)

以下是ant联机帮助页的摘录。希望这有帮助。

-lib <path>
              specifies a path to search for jars and classes

答案 1 :(得分:0)

所以只是为了报告社区,我找到了我的问题的解决方案,也许是一些开发人员使用ant来编译android applications with external .jars的问题。

确保您的jar文件立即位于libs文件夹中,而不是libs的某个子文件夹中。似乎ant 以递归方式搜索.jar文件的lib子文件夹。

再次运行脚本,包含库依赖项并从脚本中删除错误。希望它有所帮助!