Android: How to Install the Instrumentation APK onto an AVD in a Headless Host
Asked Answered
C

6

6

I'm trying to integrate Android JUnit tests with our Bamboo Ant builds. I've already tested the setup locally, and I'm able to run tests.

But when I tried the same setup in our Bamboo server, I get the following error when running the tests:

INSTRUMENTATION_STATUS: id=ActivityManagerService
INSTRUMENTATION_STATUS: Error=Unable to find instrumentation info for: ComponentInfo{com.synapticstuff.guitartabs/pl.polidea.instrumentation.PolideaInstrumentationTestRunner}
INSTRUMENTATION_STATUS_CODE: -1
android.util.AndroidException: INSTRUMENTATION_FAILED: com.synapticstuff.guitartabs/pl.polidea.instrumentation.PolideaInstrumentationTestRunner

Note that I used a custom library for Instrumentation (http://code.google.com/p/the-missing-android-xml-junit-test-runner/), so that I can pull the JUNit xml test results and feed it to Bamboo.

Also, the build agent used in creating the build is an Ubuntu VM, which doesn't have any GUI so I need to do everything via command line. An AVD is already running on that VM.

I did encounter the same problem when I first ran the adb shell am instrument .. <snip> command locally, and I found it weird it worked after running the test from Eclipse.

Looking up the error log, the Android Instrumentation Framework article tells me that

"It's possible that the instrumentation apk isn't installed on your device or that the package name is incorrect in the Manifest file."

so it must be that the instrumentation apk isn't installed.

So, how do I install the instrumentation apk onto the AVD?

Thanks!

Cary answered 7/7, 2011 at 11:17 Comment(0)
P
3

There are probably multiple situations that can cause this error, but I got it from not having an instrumented version of the test package installed on the emulator. Documentation is a bit scant, but I don't think there's an "instrumentation APK" that you install onto the emulator (at least I couldn't find such a thing); you build your test application with instrumentation included. Anyway, this is how I run tests from the command line using ant, which now works:

ant instrument install test

and this also works running on Jenkins using the Android emulator plugin (https://wiki.jenkins-ci.org/display/JENKINS/Android+Emulator+Plugin). I found the instrument task in the command line build documentation here: http://developer.android.com/tools/building/building-cmdline.html.

Prehistoric answered 8/2, 2013 at 3:38 Comment(0)
F
2

There is another possible reason: the package name is incorrect in the Manifest file.

Check the package name in your unit test project's manifest file first!

Fard answered 2/8, 2011 at 5:54 Comment(0)
L
1

I am also one of the few people who downloaded that custom InstrumentationTestRunner (http://code.google.com/p/the-missing-android-xml-junit-test-runner/) and I am currently stuck on this issue! I get the same error message, unfortunately I do not know the answer right now, but will update when I discover something helpful. In the meantime I looked for other options like this person's Test Runner: http://www.alittlemadness.com/2010/07/14/android-testing-xml-reports-for-continuous-integration/

There is also another discussion related to continuous integration: How to Generate Android Testing Report in HTML Automatically

Lively answered 12/9, 2011 at 19:23 Comment(0)
D
1

you can maybe solve this, if you add to your build script:

adb install -r testproject/bin/testproject.apk

checkout first how the apk-file is being named, because i still didn't figure out, how ant is going to do that exactly, but it's being created usually in bin directory.

See also the official android documentation.

Duumvirate answered 4/4, 2012 at 13:51 Comment(0)
M
0

I ran into this problem when running my tests against an old Android 1.5 virtual device. After switching to a 2.3.3 virtual device the problem went away. I don't know if the problem is due to the virtual device OS being old or the virtual device being created with old Android SDK tools.

Mackmackay answered 26/9, 2013 at 8:21 Comment(0)
B
-1

I was running into the exact same problem with running an android build under Bamboo. I found that for some reason the android:targetPackage element in my test project manifest was incorrect. It was set to be the package of my main project, not the test project. For some reason running when running the tests in eclipse eveything worked fine, but it died when I tried to run the ant test at the command line. The instrumentation instrumentation tag read:

<instrumentation
    android:name="android.test.InstrumentationTestRunner"
    android:targetPackage="com.example.blah" />

This was automatically generated by eclipse when I created the project. I changed it to read:

<instrumentation
    android:name="android.test.InstrumentationTestRunner"
    android:targetPackage="com.example.blah.test" />

and suddenly everything ran fine.

Before answered 10/12, 2012 at 3:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.