android-test icon indicating copy to clipboard operation
android-test copied to clipboard

Running tests with ActivityScenario on Andriod 13 device with the targetSdk 33 throws the ActivityNotFoundException

Open dudka-dev opened this issue 2 years ago • 2 comments

Description

After upgrading targetSdk to 33 Android tests on Android 13 device start to fail with the exception:

android.content.ActivityNotFoundException: Unable to find explicit activity class {com.appsflyer.engagement.test/androidx.test.core.app.InstrumentationActivityInvoker$BootstrapActivity}; have you declared this activity in your AndroidManifest.xml, or does your intent not match its declared <intent-filter>?

Steps to Reproduce

Precondition: Android 13 device targetSdk 33

Run some test: ActivityScenario.launch( TestActivity::class.java )

Expected Results

Test should pass

Actual Results

Test fails with exception: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.appsflyer.engagement.test/androidx.test.core.app.InstrumentationActivityInvoker$BootstrapActivity}; have you declared this activity in your AndroidManifest.xml, or does your intent not match its declared <intent-filter>?

AndroidX Test and Android OS Versions

androidTestImplementation 'androidx.test:runner :1.4.0' targetSdk 33 Android 13

Link to a public git repo demonstrating the problem:

dudka-dev avatar Jul 01 '22 08:07 dudka-dev

Same issue with 1.5.0-alpha01.

pazlavi avatar Jul 04 '22 08:07 pazlavi

Also hit this issue. As a temporary workaround, I had success adding the following to the AndroidManifest.xml under our androidTest source directory. It removes the <intent-filter> components from the problematic <activity> components, so that explicit Intents work again.

<activity
    android:name="androidx.test.core.app.InstrumentationActivityInvoker$BootstrapActivity"
    tools:node="merge">
    <intent-filter tools:node="removeAll" />
</activity>
<activity
    android:name="androidx.test.core.app.InstrumentationActivityInvoker$EmptyActivity"
    tools:node="merge">
    <intent-filter tools:node="removeAll" />
</activity>

It is possible that there is some AndroidX test code that relies on the <intent-filter>. I didn't observe any issues in our repo, but results could vary.

codylund avatar Jul 15 '22 20:07 codylund

I've also run into this issue ... Any word on a fix?

Bradleycorn avatar Aug 01 '22 20:08 Bradleycorn

We're working on a fix, stay tuned...

brettchabot avatar Aug 09 '22 17:08 brettchabot

Fixed in androidx.test:core:1.5.0-alpha02

brettchabot avatar Aug 25 '22 17:08 brettchabot

Note that if targeting 12+, you have to specify android:exported

or you will experience a build failure:

android:exported needs to be explicitly specified for element
<activity#androidx.test.core.app.InstrumentationActivityInvoker$BootstrapActivity>. 

Apps targeting Android 12 and higher are required to specify an explicit value for 
`android:exported` when the corresponding component has an intent filter defined. 

See https://developer.android.com/guide/topics/manifest/activity-element#exported for details.

elevenfive avatar Oct 14 '22 22:10 elevenfive

Didn't have the xmlns:tools attribute in the manifest and android:exported was missing from the activities. The full version looks like this:

<manifest
  …
  xmlns:tools='http://schemas.android.com/tools'
>
  <application
  …
  >
    …
    <activity
      android:exported='true'
      android:name='androidx.test.core.app.InstrumentationActivityInvoker$BootstrapActivity'
      tools:node='merge'
    >
      <intent-filter
        tools:node='removeAll'
      ></intent-filter>
    </activity>
    <activity
      android:exported='true'
      android:name='androidx.test.core.app.InstrumentationActivityInvoker$EmptyActivity'
      tools:node='merge'
    >
      <intent-filter
        tools:node='removeAll'
      ></intent-filter>
    </activity>
  </application>
  …
</manifest>

krischik avatar Jan 23 '23 18:01 krischik