Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
dudka-dev opened this issue Jul 1, 2022 · 7 comments · Fixed by android/nowinandroid#208

Comments

@dudka-dev
Copy link

dudka-dev commented Jul 1, 2022

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 dudka-dev changed the title Running a test with ActivityScenario with Running a test with ActivityScenario with targetSdk 33 throws the ActivityNotFoundException Jul 1, 2022
@dudka-dev dudka-dev changed the title Running a test with ActivityScenario with targetSdk 33 throws the ActivityNotFoundException Running a test with ActivityScenario with the targetSdk 33 on Andriod 13 device throws the ActivityNotFoundException Jul 1, 2022
@dudka-dev dudka-dev changed the title Running a test with ActivityScenario with the targetSdk 33 on Andriod 13 device throws the ActivityNotFoundException Running tests with ActivityScenario on Andriod 13 device with the targetSdk 33 throws the ActivityNotFoundException Jul 1, 2022
@pazlavi
Copy link

pazlavi commented Jul 4, 2022

Same issue with 1.5.0-alpha01.

@codylund
Copy link

codylund commented Jul 15, 2022

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
Copy link

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

@brettchabot
Copy link
Collaborator

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

@brettchabot
Copy link
Collaborator

Fixed in androidx.test:core:1.5.0-alpha02

1fish2 added a commit to 1fish2/BBQTimer that referenced this issue Aug 27, 2022
Need `androidx.test:core:1.5.0-alpha02` to fix android/android-test#1412 in Espresso: `android.content.ActivityNotFoundException: Unable to find explicit activity class InstrumentationActivityInvoker$BootstrapActivity`.
@elevenfive
Copy link

elevenfive commented Oct 14, 2022

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
Copy link

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

<manifestxmlns: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>

hamiltont added a commit to hamiltont/iNaturalistAndroid that referenced this issue Dec 27, 2023
We're using an out-of-date androidx.test package. Rather than upgrading, which can be quite complex
occasionally, I'm just fixing the concrete issue being encountered by the CI/CD for SDK 33 testing

See android/android-test#1412 for details of the issue
hamiltont added a commit to hamiltont/iNaturalistAndroid that referenced this issue Dec 27, 2023
Upgraded the androidx.test.core to address this issue: android/android-test#1412

Still having issues with flaky tests on SDK 33. Appears the way that focus is handled in
the application is problematic for espresso. A quick look turned up some non-obvious code
(the code under test handles clicks but returns false indicating that it did not handle
them, and the view is a nest of activity-fragment-fragment that will take me a moment to
unpack).

Chose to just maintain the SDK that was being tested previosuly (30) but put 33 into the
list as something to be fixed
hamiltont added a commit to hamiltont/iNaturalistAndroid that referenced this issue Dec 27, 2023
Upgraded the androidx.test.core to address this issue: android/android-test#1412

Still having issues with flaky tests on SDK 33. Appears the way that focus is handled in
the application is problematic for espresso. A quick look turned up some non-obvious code
(the code under test handles clicks but returns false indicating that it did not handle
them, and the view is a nest of activity-fragment-fragment that will take me a moment to
unpack).

Chose to just maintain the SDK that was being tested previosuly (30) but put 33 into the
list as something to be fixed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants