Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Espresso Driver: Instrumentation permission denial, package does not have signature matching target #791

Open
KimEklund13 opened this issue Jun 13, 2022 · 6 comments

Comments

@KimEklund13
Copy link

Hello,

I'm on Mac OS 12.4 Monterey running Appium Desktop 1.22.3 and the separate inspector tool 1.22.3, along with Gradle v 6.5. When trying to connect Appium to my APK on my emulator (API 30), I keep getting this error:

[Instrumentation] INSTRUMENTATION_STATUS: Error=Permission Denial: starting instrumentation ComponentInfo{io.appium.espressoserver.test/androidx.test.runner.AndroidJUnitRunner} from pid=4647, uid=4647 not allowed because package io.appium.espressoserver.test does not have a signature matching the target

I cleaned our project in Android Studio, wiped the emulator and reinstalled the build, and I still get this issue.
When I build from the command line instead of using Android Studio using ./gradlew installDebug, the issue is the same.

I've tried 30+ stackoverflow pages with varying solutions that don't work, including adding additional dependencies in the Android Manifest, adding appium:allowTestPackages as a desired capability, etc.

It's important to note that I can successfully connect using the UIAutomator2.

@KazuCocoa
Copy link
Member

Could you share the full appium log as GitHub GIST?


Generally, the app under test and the espresso server must have the same signature. Appium espresso driver manages them in the new session request process.

If they have the same signature, below command will print the same info.

apksigner.jar verify --print-certs /your/espresso/server.apk
apksigner.jar verify --print-certs /your/the/app/under/test.apk

@KazuCocoa
Copy link
Member

https://github.com/appium/appium-espresso-driver#requirements

Both the server package and the application under test must be signed with the same digital signature. Appium does sign them automatically upon session creation, so this could only be an issue if one wants to test an application, which is already installed on the device (using noReset=true capability).

@KimEklund13
Copy link
Author

KimEklund13 commented Jun 14, 2022

@KazuCocoa here is the appium log gist

I also created a brand new blank app and tried doing the same thing with connecting with Espresso driver and got the same signature mismatch error. In any case, here are the signatures from my original AUT and Espresso server APK (which clearly have a mismatch.) What would be the solution / happy path for connecting appium w/ espresso driver to my AUT without running into this error consistently?

Signatures:

espresso server:
Verified using v1 scheme (JAR signing): true
Verified using v2 scheme (APK Signature Scheme v2): true
Verified using v3 scheme (APK Signature Scheme v3): false
Verified using v3.1 scheme (APK Signature Scheme v3.1): false
Verified using v4 scheme (APK Signature Scheme v4): false
Verified for SourceStamp: false
Number of signers: 1
Signer #1 certificate DN: C=US, O=Android, CN=Android Debug
Signer #1 certificate SHA-256 digest: c4000d36f61cc13db0ab827d82f46acc2ae7e84ec9d9d67f295eec0a968a9c88
Signer #1 certificate SHA-1 digest: 0740bdc0ea0b983cfd9e87c85fc831b087eb3404
Signer #1 certificate MD5 digest: 00baa15a5c135fea98b9092f4762be02
Signer #1 key algorithm: RSA
Signer #1 key size (bits): 2048
Signer #1 public key SHA-256 digest: 59966535e4e4342dbb90654aca54f810994c75d0a0da2e2e6b4aa43010904baf
Signer #1 public key SHA-1 digest: de71ae7494cedce98d84a1915c44ad3db2e11bce
Signer #1 public key MD5 digest: 4570d120993f246f6d2e63937ede14c9

AUT:
Verified using v1 scheme (JAR signing): true
Verified using v2 scheme (APK Signature Scheme v2): true
Verified using v3 scheme (APK Signature Scheme v3): false
Verified using v3.1 scheme (APK Signature Scheme v3.1): false
Verified using v4 scheme (APK Signature Scheme v4): false
Verified for SourceStamp: false
Number of signers: 1
Signer #1 certificate DN: C=US, O=Android, CN=Android Debug
Signer #1 certificate SHA-256 digest: a73157244191af0f529de1131e420bbaff36cfaa530a467d1b8bfc7e65b0370c
Signer #1 certificate SHA-1 digest: 02a31aac13cdd0fd542f451c7d6446ac985b5fd3
Signer #1 certificate MD5 digest: 19850be85c992362f590a9f4193f0137
Signer #1 key algorithm: RSA
Signer #1 key size (bits): 2048
Signer #1 public key SHA-256 digest: 1e2e391e0682ae2707ae7d5e164ad62ddad71ca313b27445228001cbbe84c533
Signer #1 public key SHA-1 digest: 0f6257553fd47ca4f75ea0ba3e0c9abadd0cc60b
Signer #1 public key MD5 digest: 06047a7cc8ec90cabf8b9cb135d664be

As a side note:
If I provide the app path + app activity in the desired capabilities, I can get around this error BUT I get a different error regarding androidx/lifecycle/Lifecycle$Event:
[Espresso] java.lang.NoSuchMethodError: No static method lifecycleEventObserver(Ljava/lang/Object;)Landroidx/lifecycle/LifecycleEventObserver; in class Landroidx/lifecycle/Lifecycling; or its super classes (declaration of 'androidx.lifecycle.Lifecycling' appears in /data/app/~~-iS6xaIhrfw6zKeGRCNrhw==/io.appium.espressoserver.test-wcmXG1ZlXfo_eOFqcTERVw==/base.apk)

... I tried the solution posted in another thread with adding the additional capability espressoBuildConfig:
espressobuildconfig": "{ “additionalAppDependencies”: “androidx.lifecycle:lifecycle-extensions:2.3.1” }" but I got the same error as before / no changes.

Thanks for your help, it's much appreciated! If I can get this resolved I will probably cry tears of happiness.

@KimEklund13
Copy link
Author

Update: I was able to get around this by using the desired cap forceEspressoRebuild... though that doesn't seem like the best solution.

I'm running into a new error now with a dependency for my AUT.

java.lang.NoSuchMethodError: No virtual method addOnContextAvailableListener(Landroidx/activity/contextaware/OnContextAvailableListener;)V in class Landroidx/appcompat/app/AppCompatActivity; or its super classes (declaration of 'androidx.appcompat.app.AppCompatActivity' appears in /data/app/~~gLeNIL_ZctaVfPNHa57SEg==/com.example.myApplication--bNQEXbOq5Hzwz4r2YOXfg==/base.apk)

@amir-lili
Copy link

amir-lili commented Nov 15, 2023

I am running exact to same issue!
with UI Automator everything is working nice, when change automationName to Espresso i got this

[debug] [EspressoDriver@b837 (ab84baf3)] Proxying [GET /status] to [GET http:https://127.0.0.1:8300/status] with no body
[EspressoDriver@b837 (ab84baf3)] socket hang up

[debug] [EspressoDriver@b837 (ab84baf3)] [Instrumentation] INSTRUMENTATION_STATUS: Error=Permission Denial: starting instrumentation ComponentInfo{io.appium.espressoserver.test/androidx.test.runner.AndroidJUnitRunner} from pid=2914, uid=2000 not allowed because package io.appium.espressoserver.test does not have a signature matching the target ****.**

[debug] [EspressoDriver@b837 (ab84baf3)] INSTRUMENTATION_STATUS: id=ActivityManagerService

[debug] [EspressoDriver@b837 (ab84baf3)] [Instrumentation] INSTRUMENTATION_STATUS_CODE: -1

@VadimToptunov
Copy link

@amir-lili , to resolve the issue, you should create either your own keystore or ask a dev to provide one, then add use the following desired capabilities:
{ "platformName": "Android", "appium:automationName": "Espresso", "appium:appPackage": "com.example.myapp", "appium:appActivity": ".MainActivity", "appium:app": "/apps/app-debug.apk", "appium:platformVersion": "11.0", "appium:udid": "emulator-5554", "appium:noReset": false, "appium:showGradleLog": true, "appium:forceEspressoRebuild": true, "appium:useKeystore": true, "appium:keystorePath": "TestKeystore", "appium:keystorePassword": "KeystorePassword123", "appium:keyAlias": "KeystoreAlias", "appium:keyPassword": "KeyPassword123" }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants