Thursday, 24 June 2021

Android, run regular app in instrumentation mode (adb + debug only)

I'd like to run an Android app in a way that it can access InstrumentationRegistry.getInstrumentation() during the runtime.

This is only for debug builds and installing the app through ADB is sufficient. Because I don't want to use the instrumentation test-suite, I don't want to use InstrumentationTestRunner but launch the MainActivity of the app directly.

How is this possible?

What I've tried:

  1. Added regular implementation dependency on test packages (instead of test only dependency) - worked
    implementation 'androidx.test.uiautomator:uiautomator:2.2.0'
    implementation 'androidx.test:runner:1.1.0'
  1. Added instrumentation to manifest
    <instrumentation android:name=".MainActivity"
        android:targetPackage="com.android.shell"
        android:label="App" />

(Not sure whether this is actually correct.)

  1. Ran the app using (app already installed on the device)
adb shell am instrument -w com.example.app/.MainActivity         

This results in:

android.util.AndroidException: INSTRUMENTATION_FAILED: com.example.app/com.example.app.MainActivity
    at com.android.commands.am.Instrument.run(Instrument.java:519)
    at com.android.commands.am.Am.runInstrument(Am.java:202)
    at com.android.commands.am.Am.onRun(Am.java:80)
    at com.android.internal.os.BaseCommand.run(BaseCommand.java:60)
    at com.android.commands.am.Am.main(Am.java:50)
    at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
    at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:399)

So essentially my question is, how do I achieve running the app in a way I can use UiAutomator during the runtime?

Thanks in advance!



from Android, run regular app in instrumentation mode (adb + debug only)

No comments:

Post a Comment