Tuesday, June 8, 2010

Android Instrumentation Testing - A Permission Denial Issue

On a project I am working with, I ran into an issue where the android instrumentation test runner (android.test.InstrumentationTestRunner) was complaining that my test package's signature did not match the signature for the target package. I pulled my hair out for a while trying to figure out what was going on.

Here is the error I got:

INSTRUMENTATION_STATUS: id=ActivityManagerService
INSTRUMENTATION_STATUS: Error=Permission Denial: starting instrumentation ComponentInfo{com.myapp.tests/android.test.InstrumentationTestRunner} from pid=2036, uid=2036 not allowed because package com.myapp.tests does not have a signature matching the target com.myapp
INSTRUMENTATION_STATUS_CODE: -1
java.lang.SecurityException: Permission Denial: starting instrumentation ComponentInfo{com.myapp.tests/android.test.InstrumentationTestRunner} from pid=2036, uid=2036 not allowed because package com.myapp.tests does not have a signature matching the target com.myapp


Solution:

It turned out that the test package's make file had referenced "LOCAL_CERTIFICATE := shared" whereas the target package's makefile was missing this line. I just needed to comment out the LOCAL_CERTIFICATE line so that it matched the target package's makefile.

Apparently, if no certificate directives are given in the makefiles, the android build system defaults to a debug certificate. I have not needed to drill down into the whole signatures topic so far, but this information clears up how to get around the permissions denial issue i was seeing. A google search brought up some information, but not for this specific case. One set of links that got me started though is at a mailing list archive post on osdir.com.

Android's Build Cookbook has some good information mentioning the LOCAL_CERTIFICATE value.

No comments: