Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build an android test app with a dependency on another app using ant?

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.

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.

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.

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.

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.

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]                ^
like image 944
emmby Avatar asked Mar 17 '10 22:03

emmby


2 Answers

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

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

like image 178
Christopher Orr Avatar answered Nov 02 '22 12:11

Christopher Orr


I ran into this exact issue.

For me the solution was to add the following to my ant.properties.

tested.project.dir=../MyApp

Christopher's answer will also generate an ant.properties file for you. His solution is better if you do not already have a fully functioning project in Eclipse.

For me, my project was already building and working in Eclipse, but would not build in ant. To accomplish this, I only needed the above in my ant.properties. Eclipse and other IDE's do not generate the proper ant.properties for you, hence Christopher's answer will work because it generates ant.properties.

like image 25
stevebot Avatar answered Nov 02 '22 11:11

stevebot