How to get Instrumentation object from outside tests
<p>I need to test my UI on android using UiAutomation and UiDevice which I get from Instrumentation. To get the Instrumentation object from testing area, I just add <em>testInstrumentationRunner</em> in my .gradle file and get the object from</p>

<p><code>InstrumentationRegistry.getInstrumentation()</code></p>

<p>However when I call the above method from my activity class, I get the following exception:</p>

<blockquote>
  <p>java.lang.IllegalStateException: No instrumentation registered! Must run under a registering instrumentation.</p>
</blockquote>

<p>I have tried registering instrumentation in my <em>AndroidManifest</em> file, but the error persists. Also in the instrumentation tag targetPackage does not recognize my package and shows in red:</p>

<p><a href="https://i.stack.imgur.com/bUaL8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bUaL8.png" alt="instrumentation tag"></a></p>

<p>How can I get the Instrumentation object from outside the testing class?</p>