android / android-test

An extensive framework for testing Android apps
https://android.github.io/android-test
Apache License 2.0
1.15k stars 310 forks source link

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

Closed dudka-dev closed 2 years ago

dudka-dev commented 2 years ago

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:

pazlavi commented 2 years ago

Same issue with 1.5.0-alpha01.

codylund commented 2 years ago

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.

Bradleycorn commented 2 years ago

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

brettchabot commented 2 years ago

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

brettchabot commented 2 years ago

Fixed in androidx.test:core:1.5.0-alpha02

elevenfive commented 1 year ago

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.
krischik commented 1 year ago

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>