8

I use Instrumentation to test PhoneApp I wrote my test application via Instrumentation

I created apk and installed it on Nexus One - Android Phone - this passed In my code I am using internal classes that are not a part of standard SDK. I build it not in Eclipse but in my embedded env. I am eng in company that developing for Android so I have and Android tree with all internals libraries.

I use appropriate permissions in my manifest .

my apk created probably signed with some signature !! But probably this signature not good enough.

Now I run test via adb and got this error immediately:

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

Please help.

9 Answers 9

5

Did you find a solution to this problem? I can reproduce this when I have a test apk still installed on the device that was signed with another key.

So in order to fix execute first adb uninstall with both the package of your app and the package of your tests.

adb uninstall com.android.phone
adb uninstall com.android.phonetests
0
2

This is an

'signature matching'

issue. Make sure the APK of the test project and the APK of its target project are signed with the same certificate.

1
  • I wasted so much time on this - I was using a debug build and thought there was no way this could be the issue since my default buildType didn't set a signingConfig. I was wrong, because the project had defined a signingConfigs.debug, which is implicitly used as the signingConfig for debug! Thank you so much! Commented Jan 27, 2023 at 9:56
1

I think the problem might be the certificate used to sign your "main" app and your test app is different. I assume your test app is defining itself as an instrumentation of your main app. Doing this allows your test app to run in the main app's process, access its classes, etc, and thus for security reasons the two apps must be signed with the same certificate.

The answer is from this forum.

1
  • You see When I am my app on our platform (Phone device) I don't get such Permission Denial !! This happens only if I installed and run my apk on reference phone for example Nexus One of Google or any other. My app testing phone app that is running on Phone ??
    – ilana
    Commented Jun 21, 2010 at 7:55
1

Clean your project, and build immediately. And look in your AndroidManifest if there is an itent like this :

category android:name="android.intent.category.LAUNCHER"
1

The error is because your are testing a system permission level application and the application to be tested should be in system/data and application_test project can be installed in data/app

0

I fixed the same problem by adding the certificate that signed my application under test as was described in Android Developers site: In Eclipse: go to Windows > Preferences > Android > Build and add in Custom debug keystore your application keystore.

Rebuild the tests package and you should be good to go.

Hope this helps.

0

This problem can be solved by uninstalling the apk file and the test application from the emulator. And then resign the application with re-sign.jar and then install the apk and then run the test app.

0

Had a similar issue with no luck getting any signatures to agree.

Using a debug application build (./gradlew assembleDebug) instead of release can help circumvent the issue altogether because debug apps don't need to be signed before they're installed.

0

This solution is only for system app

In my case, this error occur when I create InstrumentationTest case for existing system app (We are building our own android OS based on AOSP)

We normally build the apk using mm command based on Android.mk file, here the key is LOCAL_CERTIFICATE.

Find Android.mk in Targeted system app and the test case project developing by you.

system app's Android.mk LOCAL_CERTIFICATE value should match with InstrumentationTest case project's Android.mk LOCAL_CERTIFICATE value

Good luck!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.