24

I need to compile an application with system permissions in order to use target application com.android.settings. For now while I try to run my apk I get the error message

Test run failed: Permission Denial: starting instrumentation ComponentInfo{com.jayway.test/android.test.InstrumentationTestRunner} from pid=354, uid=354 not allowed because package com.jayway.test does not have a signature matching the target com.android.settings

How can I compile my application with system permissions?

DeRagan
  • 21,854
  • 6
  • 38
  • 50
Michalis
  • 2,959
  • 6
  • 23
  • 23
  • 4
    You can only sign your application with the system signing key if you are creating your own firmware. – CommonsWare Aug 30 '10 at 08:35
  • I would like to experiment with Android Emulator first. Can I compile Android Emulator by selecting `debug` option with `choosecombo` command and then try to install my own application? – Michalis Aug 30 '10 at 09:49
  • See answer here: http://stackoverflow.com/questions/5383401/android-inject-events-permission/21555223#21555223 – wwjdm Feb 04 '14 at 14:34

3 Answers3

30

After having some search I found how to sign my application with system (platform) key. System signatures are located in directory <root-of-android-source-tree>/build/target/product/security. You can use them to sign your application with system privileges.

Michalis
  • 2,959
  • 6
  • 23
  • 23
  • Great! Thanks very much, Mich! – Albus Dumbledore Jul 18 '11 at 13:00
  • 1
    to build a system application to add to the firmware, is it necessary to export the APK? I've managed to get Google's certificate/keystore and I am able to run the app as a system app in the emulator but now I need to give this app to the firmware engineer and I'm not sure how to build it. – Someone Somewhere Oct 19 '11 at 20:07
  • I wonder if the .apk in /bin would work since it's been signed with google_certificate.keystore – Someone Somewhere Oct 19 '11 at 20:14
  • From your link, adb install YourApp-signed.apk doesn't work because: PackageManager(432): Cannot install platform packages to user storage – barkside Feb 14 '13 at 15:42
  • 30
    Link is dead, anyone have a cached copy? This is why you are supposed to give a comprehensive answer, not a link. – matt5784 Jul 22 '13 at 22:21
  • 8
    ``/build/target/product/security` I don't get this where to find this.. any help? :) – mboy Oct 13 '16 at 09:05
2
  1. Add to manifest android:sharedUserId="android.uid.system"

  2. Download System signatures files: platform.x509.pem platform.pk8

link: https://android.googlesource.com/platform/build/+/android-8.0.0_r17/target/product/security/

  1. Sign app through terminal (java -jar signapk.jar platform.x509.pem platform.pk8 unsigned.apk signed.apk) (first you must put all files to one folder), or make certificate with keytool-importkeypair to make google_certificate.keystore and then

link for keytool-importkeypair download and explanation:

https://github.com/getfatday/keytool-importkeypair

  1. After that steps install your signed system app to your device. Good luck!!!
Marko Katic
  • 63
  • 1
  • 9
  • Is it possible to put such application in Google Store? – Spook Apr 09 '18 at 09:39
  • Is there an answer from the comment below?.. i would also like to know if it's possible publish an application in the store that has system access, probably not for public usage, but at least for private usage within enterprise. – Oscar Reyes Feb 17 '20 at 14:26
-4

The anser for me was simply delete the debug.keystore file. The default storage location for AVDs is in ~/.android/ on OS X and Linux, in C:\Documents and Settings\.android\ on Windows XP, and in C:\Users\.android\ on Windows Vista.

In Eclipse I "cleaned" the project, uninstalled the App and the TestApp from the emulator and - voila everything ran fine again.

Mike Mitterer
  • 5,309
  • 2
  • 35
  • 51
  • While this solution solved your problem, and has solved mine a few times (due to problems with expired debug keystore), this is referring to another problem. – Tim Kist Nov 29 '17 at 09:21