如何使用 ant 构建一个依赖于另一个应用程序的 android 测试应用程序? [英] How to build an android test app with a dependency on another app using ant?

查看:21
本文介绍了如何使用 ant 构建一个依赖于另一个应用程序的 android 测试应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为 MyApp 的模块,另一个名为 MyAppTests 的模块依赖于 MyApp.两个模块都生成 APK,一个名为 MyApp.apk,另一个名为 MyAppTests.apk.

I have a module called MyApp, and another module called MyAppTests which has a dependency on MyApp. Both modules produce APKs, one named MyApp.apk and the other MyAppTests.apk.

我通常在 IntelliJ 或 Eclipse 中构建这些,但为了持续集成,我想为它们创建一个 ant 构建文件.

I normally build these in IntelliJ or Eclipse, but I'd like to create an ant buildfile for them for the purpose of continuous integration.

我使用android update"为 MyApp 创建了一个构建文件,感谢 commonsware's answer 对我之前的问题我已经能够使用 ant 成功构建它.

I used "android update" to create a buildfile for MyApp, and thanks to commonsware's answer to my previous question I've been able to build it successfully using ant.

我现在想使用 ant 构建 MyAppTests.apk.我像以前一样使用android update"构建了构建文件,但是当我运行它时,我收到一条错误消息,表明它没有在 MyApp 中找到任何类.

I'd now like to build MyAppTests.apk using ant. I constructed the buildfile as before using "android update", but when I run it I get an error indicating that it's not finding any of the classes in MyApp.

从我之前的问题中得到一个问题,我尝试将 MyApp.apk 放入我的 MyAppTests/libs,但不幸的是,这并没有奇迹般地解决问题.

Taking a que from my previous question, I tried putting MyApp.apk into my MyAppTests/libs, but unfortunately that didn't miraculously solve the problem.

当它依赖于另一个 APK 中的类时,使用 ant 构建测试应用 APK 的最佳方法是什么?

What's the best way to build a test app APK using ant when it depends on classes in another APK?

$ ant debug
Buildfile: build.xml
    [setup] Project Target: Google APIs
    [setup] Vendor: Google Inc.
    [setup] Platform Version: 1.5
    [setup] API level: 3
    [setup] WARNING: No minSdkVersion value set. Application will install on all Android versions.

dirs:
     [echo] Creating output directories if needed...

resource-src:
     [echo] Generating R.java / Manifest.java from the resources...

aidl:
     [echo] Compiling aidl files into Java classes...

compile:
    [javac] Compiling 5 source files to /Users/mike/Projects/myapp/android/MyAppTests/bin/classes
    [javac] /Users/mike/Projects/myapp/android/MyAppTests/src/com/myapp/test/GsonTest.java:3: cannot find symbol
    [javac] symbol  : class MyApplication
    [javac] location: package com.myapp
    [javac] import com.myapp.MyApplication;
    [javac]                ^

推荐答案

/Users/mike/Projects/myapp/android/ 中,假设主应用程序源在名为 MyApp,运行:
android create test-project -p MyAppTests -m ../MyApp -n MyAppTests

In /Users/mike/Projects/myapp/android/, assuming that the main app source is in a subdirectory called MyApp, run:
android create test-project -p MyAppTests -m ../MyApp -n MyAppTests

这将生成一个测试文件夹结构和适当的 Ant 构建文件,因此您可以执行以下操作:
cd MyAppTests
ant 运行测试

That will generate a test folder structure and appropriate Ant build files, so you can then do:
cd MyAppTests
ant run-tests

这篇关于如何使用 ant 构建一个依赖于另一个应用程序的 android 测试应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆