android-test
android-test copied to clipboard
Running tests with ActivityScenario on Andriod 13 device with the targetSdk 33 throws the ActivityNotFoundException
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:
Same issue with 1.5.0-alpha01
.
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.
I've also run into this issue ... Any word on a fix?
We're working on a fix, stay tuned...
Fixed in androidx.test:core:1.5.0-alpha02
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.
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>