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

Instrumented test execution with ANDROIDX_TEST_ORCHESTRATOR does not work with Android 11 #743

Closed
mateuszkwiecinski opened this issue Sep 15, 2020 · 70 comments · Fixed by #777
Assignees

Comments

@mateuszkwiecinski
Copy link

mateuszkwiecinski commented Sep 15, 2020

Description

Similar to #355, but the execution hangs

Steps to Reproduce

  1. Create new project using AS wizard
  2. Enable Android orchestrator following the https://developer.android.com/training/testing/junit-runner
  3. Run tests on Android Emulator with API 30

Expected Results

The test passes

Actual Results

  • The test hangs
  • logcat shows:
2020-09-15 21:28:39.486 12791-12791/com.example.myapplication E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.myapplication, PID: 12791
    java.lang.RuntimeException: Exception thrown in onCreate() of ComponentInfo{com.example.myapplication.test/androidx.test.runner.AndroidJUnitRunner}: java.lang.RuntimeException: Cannot connect to androidx.test.orchestrator.OrchestratorService
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6709)
        at android.app.ActivityThread.access$1300(ActivityThread.java:237)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1913)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7656)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
     Caused by: java.lang.RuntimeException: Cannot connect to androidx.test.orchestrator.OrchestratorService
        at androidx.test.orchestrator.instrumentationlistener.OrchestratedInstrumentationListener.connect(OrchestratedInstrumentationListener.java:93)
        at androidx.test.runner.AndroidJUnitRunner.onCreate(AndroidJUnitRunner.java:309)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6704)
        at android.app.ActivityThread.access$1300(ActivityThread.java:237) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1913) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:223) 
        at android.app.ActivityThread.main(ActivityThread.java:7656) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 
2020-09-15 21:28:39.486 12791-12791/com.example.myapplication E/AndroidJUnitRunner: An unhandled exception was thrown by the app.
2020-09-15 21:28:39.493 12791-12791/com.example.myapplication E/InstrumentationResultPrinter: Failed to mark test No Tests as finished after process crash
  • (might be unrelated, but doesn' happen on api 29) my private app shows in addition: mkdir: ‘/storage/emulated/0/Android/data/my.app.package’: Permission denied which points at DeviceProviderInstrumentTestTask and getAdditionalTestOutputEnabled which tries to save some log file. disabling the android.enableAdditionalTestOutput property removes the mkdir error but the test still hangs

AndroidX Test and Android OS Versions

    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    androidTestImplementation 'androidx.test:runner:1.3.0'
    androidTestUtil 'androidx.test:orchestrator:1.3.0'

Android OS Versions: the issue exists only on API 30. The test passes on lower apis.

Link to a public git repo demonstrating the problem:

https://github.com/mateuszkwiecinski/orchestrator_doesnt_work
task: ./gradlew connectedDebugAndroidTest hangs and never ends
image

Github action run confirming the issue: https://github.com/mateuszkwiecinski/orchestrator_doesnt_work/pull/1/checks?check_run_id=1119649523

@prfarlow1
Copy link

I am also experiencing this bug. I also made a test application that experiences the same indefinite hanging on Android 11: https://github.com/prfarlow1/UiTestApplication

@LmKupke
Copy link

LmKupke commented Sep 21, 2020

Same issue is occurring when compiling and targeting SDK 30 and running against an emulator with 30.

2020-09-21 14:26:44.942 31419-31419/com.scompany.consumer E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.scompany.consumer, PID: 31419
java.lang.RuntimeException: Exception thrown in onCreate() of ComponentInfo
java.lang.RuntimeException: Cannot connect to androidx.test.orchestrator.OrchestratorService
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6709)
at android.app.ActivityThread.access$1300(ActivityThread.java:237)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1913)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: java.lang.RuntimeException: Cannot connect to androidx.test.orchestrator.OrchestratorService

  • no issue when compiling and targeting 30 and running on an emulator with 29.
  • no issue when compiling and targeting 29 and running on an emulator with 30.

@prfarlow1
Copy link

Can we get an update from the Android test team when this will be addressed? This is a really bad bug. We rely on the orchestrator for our tests to pass and right now we just can't run our tests on Android 11 test devices.

@nimeacuerdo
Copy link

Same here. Everything was working fine with emulator api 29 and Orchestrator until we migrated to api 30.

@brettchabot
Copy link
Collaborator

Hey all, sorry for delayed response. We are looking into this, but the fix is proving more difficult to get released than anticipated. We hope to have something out soon to address this.

@tillchen
Copy link

Same here. Switched to Android 10 and it's working fine for me.

@brettchabot
Copy link
Collaborator

Please give 1.3.1-alpha01 a try. This should hopefully be fixed.
See https://github.com/android/android-test/releases/tag/androidx-test-1.3.1-alpha01

@mateuszkwiecinski
Copy link
Author

mateuszkwiecinski commented Oct 19, 2020

Can't confirm it works :/ It doesn't hang indeed, but still fails with a message:

Task :app:connectedDebugAndroidTest
Starting 0 tests on test(AVD) - 11
Tests on test(AVD) - 11 failed: Instrumentation run failed due to 'Process crashed.'

com.android.build.gradle.internal.testing.ConnectedDevice > No tests found.[test(AVD) - 11] FAILED
No tests found. This usually means that your test classes are not in the form that your test runner expects (e.g. don't inherit from TestCase or lack @test annotations).

Failed run:
https://github.com/mateuszkwiecinski/orchestrator_doesnt_work/pull/3/checks?check_run_id=1274143298

It works on devices with api <30
image

@prfarlow1
Copy link

I also could not get my tests to work with the new 1.3.1-alpha01

@brettchabot brettchabot reopened this Oct 19, 2020
@brettchabot
Copy link
Collaborator

It looks like there is an incompatibility with the testInstrumentationRunnerArguments clearPackageData: 'true' setting. I was able to get @mateuszkwiecinski sample working by commenting out that line.

brettchabot added a commit to android/testing-samples that referenced this issue Oct 19, 2020
Enable clearPackageData
@brettchabot brettchabot self-assigned this Oct 19, 2020
@brettchabot
Copy link
Collaborator

brettchabot commented Oct 19, 2020

A workaround for the clearPackageData issue is to declare a

application android:forceQueryable="true"

in the androidTest manifest

@prfarlow1
Copy link

A workaround for the clearPackageData issue is to declare a

application android:forceQueryable="true"

in the androidTest manifest

What does android:forceQueryable="true" actually do? I can't find any documentation for it

@brettchabot
Copy link
Collaborator

Check out the docs on the new package visibility restrictions on API 30 here
https://developer.android.com/training/basics/intents/package-visibility

IIUC using forceQueryable basically lets other apps (like the orchestrator app) communicate with the test package.

copybara-service bot pushed a commit that referenced this issue Oct 19, 2020
This fixes using 'clearPackageData' on API 30 by making test apps (that build androidx.test.runner) callable from androidx.test.orchestrator.

Fixes #743

PiperOrigin-RevId: 337944463
copybara-service bot pushed a commit that referenced this issue Oct 20, 2020
This fixes using 'clearPackageData' on API 30 by making test apps (that build androidx.test.runner) callable from androidx.test.orchestrator.

Fixes #743

PiperOrigin-RevId: 337944463
@brettchabot
Copy link
Collaborator

Please give 1.3.1-alpha02 a try

@mateuszkwiecinski
Copy link
Author

Thank you @brettchabot 👍
I can confirm it works in my sample project 🚀

@brettchabot
Copy link
Collaborator

whew thanks for confirming @mateuszkwiecinski

@tadfisher
Copy link

android:forceQueryable isn't recognized by AAPT2 4.1.0 and fails the build:

Execution failed for task ':Mobile-Android:processDevDebugAndroidTestResources'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
   > Android resource linking failed
     /home/tad/simple/mobile/Mobile-Android/Mobile-Android/build/intermediates/packaged_manifests/devDebugAndroidTest/AndroidManifest.xml:22: AAPT: error: attribute android:forceQueryable not found.
         

@brettchabot
Copy link
Collaborator

are you using studio 4.2 beta 6 ?

@QAutomatron
Copy link

Using 1.4.0-alpha05 testx and Studio 4.2b6, getting "No tests to run", most probably something crashed during init phase on Android 11 emulator.

logcat said about some new permission issue:

2021-03-26 18:21:05.133 9240-9263/androidx.test.orchestrator E/OrchestrationXmlTestRunListener: Failed to generate report data
    java.io.IOException: Operation not permitted
        at java.io.UnixFileSystem.createFileExclusively0(Native Method)
        at java.io.UnixFileSystem.createFileExclusively(UnixFileSystem.java:317)
        at java.io.File.createTempFile(File.java:2018)
        at androidx.test.orchestrator.listeners.OrchestrationXmlTestRunListener.getResultFile(OrchestrationXmlTestRunListener.java:2)
        at androidx.test.orchestrator.listeners.OrchestrationXmlTestRunListener.createOutputResultStream(OrchestrationXmlTestRunListener.java:8)
        at androidx.test.orchestrator.listeners.OrchestrationXmlTestRunListener.generateDocument(OrchestrationXmlTestRunListener.java:3)
        at androidx.test.orchestrator.listeners.OrchestrationXmlTestRunListener.orchestrationRunFinished(OrchestrationXmlTestRunListener.java:4)
        at androidx.test.orchestrator.AndroidTestOrchestrator.finish(AndroidTestOrchestrator.java:1)
        at androidx.test.orchestrator.AndroidTestOrchestrator.executeNextTest(AndroidTestOrchestrator.java:2)
        at androidx.test.orchestrator.AndroidTestOrchestrator.runFinished(AndroidTestOrchestrator.java:10)
        at androidx.test.orchestrator.TestRunnable.run(TestRunnable.java:13)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:923)

I don't know what else to try.

@btseytlinTCP
Copy link

FYI 1.4.0-alpha06 released which has a fix for the forceQueryable bug: https://github.com/android/android-test/releases/tag/androidx-test-1.4.0-alpha06

@krisjwolff
Copy link

Still getting Cannot connect to androidx.test.orchestrator.OrchestratorService using alpha06 on Pixel 5 API 30.

If I explicitly install with --force-queryable as described on Feb 18, it works fine.

@brettchabot
Copy link
Collaborator

@krisjwolff what Studio + AGP version are you using?

You need to use Android Studio 4.2+ . Only in this version and later will Studio use the --force-queryable flag when installing the service apks.

@alex-tyro
Copy link

I am using 1.4.0-alpha06 and this still doesn't work for me on firebase test lab. Every other api level is fine except 11.
Firebase fails with: Cannot connect to androidx.test.orchestrator.OrchestratorService

@brettchabot
Copy link
Collaborator

@alex-tyro thanks for the report. I was able to repro on FTL and I filed bug against them. Unfortunately due to the android11 package visibility changes there is nothing we can do on the androidx.test library to address this. FTL will need the same fix as Studio: adding a '--force-queryable' flag when installing the service apks.

@krisjwolff
Copy link

@brettchabot Thank you for filing a bug with FTL. Is that ticket publicly-available, so I can watch it?

@brettchabot
Copy link
Collaborator

Unfortunately I could not find an easy way to file an publically visible bug. I can update this issue when FTL responds if that works?

@prfarlow1
Copy link

Unfortunately I could not find an easy way to file an publically visible bug. I can update this issue when FTL responds if that works?

That would be fantastic, thank you for keeping us up-to-date.

@krisjwolff
Copy link

Unfortunately I could not find an easy way to file an publically visible bug. I can update this issue when FTL responds if that works?

Yes please. That's very helpful, thanks!

@nimeacuerdo
Copy link

nimeacuerdo commented May 4, 2021

For the record, these are the versions we ended up using with Android 11 emulators and so far so good:

    espresso_version = '3.4.0-alpha02'
    androidx_test_version = '1.3.1-alpha02'

with version 30.5.4 of emulator and version 9 of system-images;android-30;google_apis;x86.

@brettchabot
Copy link
Collaborator

I'd be cautious about drawing any conclusions based on Android 11 emulators. IIUC the images are dated and do not have the final package visibility handling. In my testing I saw different behavior on Android 11 devices and Android S emulator images.

@larryng
Copy link

larryng commented May 5, 2021

I'm still seeing the issue even with installing using --force-queryable:

2021-05-05 12:36:46.126 14893-14959/? W/Binder: Caught a RuntimeException from the binder stub implementation.
    java.lang.SecurityException: Calling from not trusted UID!
        at android.app.UiAutomationConnection.throwIfCalledByNotTrustedUidLocked(UiAutomationConnection.java:525)
        at android.app.UiAutomationConnection.shutdown(UiAutomationConnection.java:429)
        at android.app.IUiAutomationConnection$Stub.onTransact(IUiAutomationConnection.java:390)
        at android.os.Binder.execTransactInternal(Binder.java:1159)
        at android.os.Binder.execTransact(Binder.java:1123)
...
2021-05-05 12:36:46.663 3626-8001/? E/MediaProvider: insertFileIfNecessary failed
    java.lang.IllegalArgumentException: Primary directory odo not allowed for content://media/external_primary/file; allowed directories are [Download, Documents]
        at com.android.providers.media.MediaProvider.ensureFileColumns(MediaProvider.java:2923)
        at com.android.providers.media.MediaProvider.ensureUniqueFileColumns(MediaProvider.java:2588)
        at com.android.providers.media.MediaProvider.insertFile(MediaProvider.java:3282)
        at com.android.providers.media.MediaProvider.insertInternal(MediaProvider.java:3826)
        at com.android.providers.media.MediaProvider.insert(MediaProvider.java:3537)
        at com.android.providers.media.MediaProvider.insertFileForFuse(MediaProvider.java:7187)
        at com.android.providers.media.MediaProvider.insertFileIfNecessaryForFuse(MediaProvider.java:7281)
2021-05-05 12:36:46.666 14866-14892/androidx.test.orchestrator E/OrchestrationXmlTestRunListener: Failed to generate report data
    java.io.IOException: Operation not permitted
        at java.io.UnixFileSystem.createFileExclusively0(Native Method)
        at java.io.UnixFileSystem.createFileExclusively(UnixFileSystem.java:317)
        at java.io.File.createTempFile(File.java:2018)
        at androidx.test.orchestrator.listeners.OrchestrationXmlTestRunListener.getResultFile(OrchestrationXmlTestRunListener.java:2)
        at androidx.test.orchestrator.listeners.OrchestrationXmlTestRunListener.createOutputResultStream(OrchestrationXmlTestRunListener.java:8)
        at androidx.test.orchestrator.listeners.OrchestrationXmlTestRunListener.generateDocument(OrchestrationXmlTestRunListener.java:3)
        at androidx.test.orchestrator.listeners.OrchestrationXmlTestRunListener.orchestrationRunFinished(OrchestrationXmlTestRunListener.java:4)
        at androidx.test.orchestrator.AndroidTestOrchestrator.finish(AndroidTestOrchestrator.java:1)
        at androidx.test.orchestrator.AndroidTestOrchestrator.executeNextTest(AndroidTestOrchestrator.java:2)
        at androidx.test.orchestrator.AndroidTestOrchestrator.runFinished(AndroidTestOrchestrator.java:10)
        at androidx.test.orchestrator.TestRunnable.run(TestRunnable.java:13)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:923)

This is with 1.4.0-alpha06 on a Pixel 3 Android 11 (RQ1A.210205.004).

@brettchabot
Copy link
Collaborator

@larryng that seems like a separate issue than the one discussed here. Can you file a new issue?

@brettchabot
Copy link
Collaborator

@krisjwolff @prfarlow1 FTL has made a fix. They expect it should get deployed in the next week or two.

@larryng
Copy link

larryng commented May 6, 2021

@brettchabot Apologies, the issue was with allure-kotlin, though the error messages in Orchestrator are a noisy red herring.

@QAutomatron
Copy link

QAutomatron commented May 6, 2021

@brettchabot Apologies, the issue was with allure-kotlin, though the error messages in Orchestrator are a noisy red herring.

have you managed to find a workaround? Can't make it work with allure-kotlin

@larryng
Copy link

larryng commented May 6, 2021

@QAutomatron Here you go. If you have any questions, please ask there instead. I don't want to continue pinging others on this thread.

@ashok07m
Copy link

I am also using testInstrumentationRunnerArguments clearPackageData: 'true'
Just update core and runner versions to make it working on android 11:

androidTestImplementation 'androidx.test:core-ktx:1.4.0-alpha04'
androidTestImplementation 'androidx.test:runner:1.4.0-alpha04'
androidTestUtil 'androidx.test:orchestrator::1.4.0-alpha04'

This solved the issue for me i.e the core,runner,rules,orchestrator test deps should be updated to same version.
now all AndroidTest cases runs in queue manner and independent of each other in my android device.

@vidushi2207
Copy link

I am observing the same issue with
androidTestUtil 'androidx.test:orchestrator:1.4.0-beta02'
androidTestImplementation 'androidx.test:rules:1.4.0-beta02'
androidTestImplementation 'androidx.test:runner:1.4.0-beta02'
and adding android:forceQueryable="true"

@fdspbsteam
Copy link

I am observing the same issue with

androidTestUtil 'androidx.test:orchestrator:1.4.1' and alpha 4 as well
androidTestImplementation 'androidx.test:rules:1.4.0
    androidTestImplementation 'androidx.test:core:1.4.0'
    // AndroidJUnitRunner and JUnit Rules
    androidTestImplementation 'androidx.test:runner:1.4.0'
    androidTestImplementation 'androidx.test:rules:1.4.0'
    
and adding android:forceQueryable="true"

this issue is hap aping in case command run via ./gradlew connectedCheck

@yogurtearl
Copy link
Contributor

related issues for docs update: https://issuetracker.google.com/issues/262661481

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.