Skip to content

Can't run test in Android #2526

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

Open
chihuy105 opened this issue Feb 14, 2025 · 36 comments
Open

Can't run test in Android #2526

chihuy105 opened this issue Feb 14, 2025 · 36 comments
Assignees

Comments

@chihuy105
Copy link

chihuy105 commented Feb 14, 2025

Steps to reproduce

Setup the patrol. And run the test

Actual results

When run patrol test in android with a Emulator that don't have Google play service (android-34/default/arm64-v8a) in German language
The test going for awhile until it got the issue. It works on IOS side

Image

Logs

Logs
Unhandled exception:
FormatException: Missing extension byte (at offset 1188)
#0      _Utf8Decoder.convertChunked (dart:convert-patch/convert_patch.dart:1950:7)
#1      _Utf8ConversionSink.addSlice (dart:convert/string_conversion.dart:304:28)
#2      _Utf8ConversionSink.add (dart:convert/string_conversion.dart:300:5)
#3      _ConverterStreamEventSink.add (dart:convert/chunked_conversion.dart:69:18)
#4      _SinkTransformerStreamSubscription._handleData (dart:async/stream_transformers.dart:111:24)
#5      _RootZone.runUnaryGuarded (dart:async/zone.dart:1609:10)
#6      _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:366:11)
#7      _BufferingStreamSubscription._add (dart:async/stream_impl.dart:297:7)
#8      _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:777:19)
#9      _StreamController._add (dart:async/stream_controller.dart:651:7)
#10     _StreamController.add (dart:async/stream_controller.dart:606:5)
#11     _Socket._onData (dart:io-patch/socket_patch.dart:2455:41)
#12     _RootZone.runUnaryGuarded (dart:async/zone.dart:1609:10)
#13     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:366:11)
#14     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:297:7)
#15     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:777:19)
#16     _StreamController._add (dart:async/stream_controller.dart:651:7)
#17     _StreamController.add (dart:async/stream_controller.dart:606:5)
#18     new _RawSocket.<anonymous closure> (dart:io-patch/socket_patch.dart:1942:33)
#19     _NativeSocket.issueReadEvent.issue (dart:io-patch/socket_patch.dart:1385:14)
#20     _microtaskLoop (dart:async/schedule_microtask.dart:40:21)
#21     _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)
#22     _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:118:13)
#23     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:185:5)

Patrol version

patrol: 3.14.0
patrol_finders: 2.7.0

Patrol Doctor output

Patrol Doctor output
Patrol doctor:
Patrol CLI version: 3.5.0
Flutter command: flutter 
  Flutter 3.27.1 • channel stable
Android: 
• Program adb found in /opt/homebrew/bin/adb
• Env var $ANDROID_HOME set to /Users/kyohuu/Library/Android/sdk
iOS / macOS: 
• Program xcodebuild found in /usr/bin/xcodebuild
• Program ideviceinstaller found in /opt/homebrew/bin/ideviceinstaller

Flutter Doctor output

Flutter Doctor output
Flutter (Channel stable, 3.27.1, on macOS 14.6.1 23G93 darwin-arm64, locale en-VN)
    • Flutter version 3.27.1 on channel stable at /Users/kyohuu/fvm/versions/3.27.1
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 17025dd882 (8 weeks ago), 2024-12-17 03:23:09 +0900
    • Engine revision cb4b5fff73
    • Dart version 3.6.0
    • DevTools version 2.40.2

@chihuy105
Copy link
Author

I found the same issue. Look like patrol not working with other language
#1334

@Kendru98 Kendru98 added the bug Something isn't working label Feb 18, 2025
@DmytroChuchmaiBarges
Copy link

@chihuy105 It seams this is caused by something else, I mean I often get the same error on en_US language.
In my case "Missing extension byte (at offset 1066)", "Missing extension byte (at offset 1287)".

@Kendru98
Copy link
Contributor

Hi, so repro steps are:

  1. Have emulator like this:
    don't have Google play service (android-34/default/arm64-v8a)
  2. Set language to German on emulator
    Correct?
  • Additional question, this is something that is 100% reproducible or this is some random error that is flaky.

@chihuy105
Copy link
Author

It happens on every run after 6 or 7 test.

  1. A emulator that don't have GG service
  2. Yes

@Kendru98
Copy link
Contributor

@chihuy105 Thanks for answer, last question, can you confirm that GG service has meaning here? If you have emulator with GG service and change language to german test pass?

@shovelmn12
Copy link

Same issue, locale is en_GB, have not tried to set to en_US:


FormatException: Missing extension byte (at offset 1484)
#0      _Utf8Decoder.convertChunked (dart:convert-patch/convert_patch.dart:1959:7)
#1      _Utf8ConversionSink.addSlice (dart:convert/string_conversion.dart:310:28)
#2      _Utf8ConversionSink.add (dart:convert/string_conversion.dart:306:5)
#3      _ConverterStreamEventSink.add (dart:convert/chunked_conversion.dart:70:18)
#4      _SinkTransformerStreamSubscription._handleData (dart:async/stream_transformers.dart:115:24)
#5      _RootZone.runUnaryGuarded (dart:async/zone.dart:1778:10)
#6      _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:381:11)
#7      _BufferingStreamSubscription._add (dart:async/stream_impl.dart:312:7)
#8      _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:798:19)
#9      _StreamController._add (dart:async/stream_controller.dart:663:7)
#10     _StreamController.add (dart:async/stream_controller.dart:618:5)
#11     _Socket._onData (dart:io-patch/socket_patch.dart:2904:41)
#12     _RootZone.runUnaryGuarded (dart:async/zone.dart:1778:10)
#13     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:381:11)
#14     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:312:7)
#15     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:798:19)
#16     _StreamController._add (dart:async/stream_controller.dart:663:7)
#17     _StreamController.add (dart:async/stream_controller.dart:618:5)
#18     new _RawSocket.<anonymous closure> (dart:io-patch/socket_patch.dart:2323:31)
#19     _NativeSocket.issueReadEvent.issue (dart:io-patch/socket_patch.dart:1646:14)
#20     _microtaskLoop (dart:async/schedule_microtask.dart:40:21)
#21     _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)
#22     _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:128:13)
#23     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:195:5)


@kubicki-4human
Copy link

Same thing. Worked fine for some time.... Will try downgrading

@shovelmn12
Copy link

@kubicki-4human did it work?

@Kendru98 any news on a fix for this issue?

@Kendru98
Copy link
Contributor

Kendru98 commented Mar 5, 2025

@shovelmn12 Hi, you also use an emulator without Google play service? There are some other priorities now, but I will forward this to team.

@shovelmn12
Copy link

@Kendru98 I am using an emulator with google play services ...

Anyways I am not using patrol anymore too many bugs and issues good luck to you :)

@Kendru98
Copy link
Contributor

Kendru98 commented Mar 5, 2025

@chihuy105 @kubicki-4human Hi guys, can you prepare minimal steps for reproduction? I was trying to reproduce this in german, and en_GB, but failed to reproduce. Or at least provide some native methods that fails in specific languages.

@chihuy105
Copy link
Author

I’m not sure but this could be the problems
I have many test case and all of it start with a native webview login usung keycloak so I do a lot of native run at the start of each test using enterTextByIndex,… native method on the webview and alot of Future.delay

@DmytroChuchmaiBarges
Copy link

DmytroChuchmaiBarges commented Mar 5, 2025

I am constantly having this error when running test in bulk i.e. without specifying a target and when I run the tests specifying the target, id does not fail. It is hard to debug though due to I need to wait about 10-20 tests to run until they fail, and the whole test process crashing.
Im my case it fails after tapping at widget with a specific key, or waitUntilVisible

@kubicki-4human
Copy link

@kubicki-4human did it work?

@Kendru98 any news on a fix for this issue?

Downgrading didn't work, but just using another instance of emulator did. Weird..

@chihuy105
Copy link
Author

what instance did you use?

@DmytroChuchmaiBarges
Copy link

It might be related to flutter/flutter#81666

@chihuy105
Copy link
Author

I think not on my case cause it’s Android

@DmytroChuchmaiBarges
Copy link

This is related to UTF8Devcoder.convertChunked which is used framework-wide.

@DmytroChuchmaiBarges
Copy link

DmytroChuchmaiBarges commented Mar 6, 2025

hey there, I found a workaround for now:
When you run the test, you see ./gradlew :app:connectedStageDebugAndroidTest -Ptarget=/Users/path_to_your_code/integration_test/test_bundle.dart -Pdart-defines=....
it might be ":app:connectedDebugAndroidTest"
So,

  1. you do the patrol build android with all the params and targets
  2. cd /android
  3. run ./gradlew :app:connectedStageDebugAndroidTest -Ptarget=/Users/path_to_your_code/integration_test/test_bundle.dart -Pdart-defines=....

in this way it does not crash the patrol process.

@chihuy105
Copy link
Author

Thanks let me check

@cljobs
Copy link

cljobs commented Apr 8, 2025

Same Issue .. Any updates?

@Kendru98
Copy link
Contributor

Kendru98 commented Apr 8, 2025

Same Issue .. Any updates?

Hi @cljobs,
It is hard to reproduce for us, can you provide some cloned repo, and specific emulator config that problem exist? Also flutter --verbose logs etc?

@jBorkowska jBorkowska self-assigned this Apr 8, 2025
@jBorkowska jBorkowska removed the bug Something isn't working label Apr 8, 2025
@jBorkowska
Copy link
Collaborator

Hi @cljobs !
As @Kendru98 wrote, we couldn't reproduce this issue before, we need more information, To be more specific:

  • a repo where we can reproduce this bug would be most useful
  • logs from logcat - my guess for now is that the real error log is there

Also it would be very useful for us to know, why your tests failed at this moment (I know, that there is no error log related to your test, but at least tell us what action should be performed in test at the moment of crash)

@jBorkowska jBorkowska added the waiting for response Waiting for user's response label Apr 8, 2025
@DmytroChuchmaiBarges
Copy link

jBorkowska please have a look at workaround I described above, it seams that the issue is in Patrol CLI since if you run the test via gradle, i runs all fine.
So somewhere in the process of running tests,I suppose there's some error happens during sending/receiving information between the patrol CLI and the app. btw, there's an open futter framework bug around this error.

@jBorkowska
Copy link
Collaborator

@DmytroChuchmaiBarges I read the thread, still we need the information I wrote about to debug it on our own

@cljobs
Copy link

cljobs commented Apr 8, 2025

I am experiencing this issue on all the Android devices I've tested. This includes a Samsung Galaxy S22, as well as Android 13 and 14 emulators, both with and without Google Play Services.

It's Logcat Error

  1. 'package:flutter_test/src/binding.dart': Failed assertion: line 1000 pos 14: '_pendingExceptionDetails != null': A test overrode FlutterError.onError but either failed to return it to its original state, or had unexpected additional errors that it could not handle. Typically, this is caused by using expect() before restoring FlutterError.onError.

  2. dart:core-patch/errors_patch.dart 50:61 _AssertionError._doThrowNew

  3. dart:core-patch/errors_patch.dart 40:5 _AssertionError._throwNew

  4. package:flutter_test/src/binding.dart 1000:14 TestWidgetsFlutterBinding._runTest.handleUncaughtError

  5. package:flutter_test/src/binding.dart 1005:9 TestWidgetsFlutterBinding._runTest.

  6. dart:async/zone.dart 1081:14 _Zone._processUncaughtError

  7. dart:async/zone.dart 1285:5 _CustomZone.handleUncaughtError

  8. dart:async/future_impl.dart 811:16 Future._propagateToListeners

  9. dart:async/future_impl.dart 674:5 Future._completeError

patrol: 3.14.1
patrol_cli: 3.5.1
androidx.test:orchestrator:1.5.1

Unfortunately, I can't share the code where the error is occurring because it belongs to my company.

@jBorkowska
Copy link
Collaborator

Thanks @cljobs . I'll try to reproduce this error.

If you're looking how to solve the error from logcat, check out this (from setup instructions):

Image

@jBorkowska jBorkowska removed the waiting for response Waiting for user's response label Apr 8, 2025
@cljobs
Copy link

cljobs commented Apr 9, 2025

I try do not modify FlutterError.onError but still error causes

It's Logcat Error

2025-04-09 10:15:16.648 606-745 ActivityManager system_server I Force stopping debug appid=10219 user=0: finished inst
2025-04-09 10:15:16.649 606-745 ActivityManager system_server I Killing 13357:.debug/u0a219 (adj 0): stop .debug due to finished inst
2025-04-09 10:15:16.651 13330-13330 app_process app_process I System.exit called, status: 0
2025-04-09 10:15:16.651 13330-13330 AndroidRuntime app_process I VM exiting with result code 0.
2025-04-09 10:15:16.652 8734-8734 BoundBrokerSvc com.google.android.gms D onUnbind: Intent { act=com.google.android.gms.measurement.START pkg=com.google.android.gms }
2025-04-09 10:15:16.653 606-745 ActivityTaskManager system_server W Force removing ActivityRecord{73a171a u0 .debug/.MainActivity} t2738 f}}: app died, no saved state
2025-04-09 10:15:16.654 877-1094 BtGatt.ScanManager com.android.bluetooth D uid 10108 isForeground true scanMode -1
2025-04-09 10:15:16.655 8734-8734 BoundBrokerSvc com.google.android.gms D onUnbind: Intent { act=com.google.android.gms.appset.service.START dat=chimera-action:/... cmp=com.google.android.gms/.chimera.GmsApiService }
2025-04-09 10:15:16.656 606-745 InputManager-JNI system_server W Input channel object '711e688 .debug/.MainActivity (client)' was disposed without first being removed with the input manager!

com....android.googlequicksearchbox W Failed to notify listeners
java.util.concurrent.CancellationException
at java.util.concurrent.FutureTask.report(FutureTask.java:121)
at java.util.concurrent.FutureTask.get(FutureTask.java:191)
at com.google.common.util.concurrent.bv.get(PG:1)
at com.google.common.util.concurrent.ed.a(PG:1)
at com.google.common.util.concurrent.cj.r(PG:2)
at com.google.common.util.concurrent.cc.run(PG:4)
at com.google.common.util.concurrent.bg.execute(PG:1)
at com.google.common.util.concurrent.bj.c(PG:1)
at com.google.common.util.concurrent.bj.b(PG:3)
at com.google.common.util.concurrent.cy.done(PG:1)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:381)
at java.util.concurrent.FutureTask.cancel(FutureTask.java:179)
at com.google.common.util.concurrent.bv.cancel(PG:1)
at com.google.android.apps.search.assistant.platform.ondevice.fulfillment.server.k.r.run(PG:1)
at com.google.apps.tiktok.tracing.eh.run(PG:2)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:463)
at com.google.common.util.concurrent.ea.a(PG:1)
at com.google.common.util.concurrent.cw.run(PG:4)
at com.google.common.util.concurrent.eb.run(PG:1)
at com.google.android.libraries.i.af.run(PG:1)
at com.google.android.libraries.i.an.run(PG:23)
at com.google.android.libraries.i.l.run(PG:2)
at com.google.android.libraries.i.q.run(PG:4)
at java.lang.Thread.run(Thread.java:1012)

java.lang.SecurityException: Caller androidx.test.services:10221 cannot post for pkg androidx.test.services in user 0
at com.android.server.notification.NotificationManagerService.resolveNotificationUid(NotificationManagerService.java:6851)
at com.android.server.notification.NotificationManagerService.cancelNotificationInternal(NotificationManagerService.java:6402)
at com.android.server.notification.NotificationManagerService$11.cancelNotification(NotificationManagerService.java:6300)
at com.android.server.am.ServiceRecord$3.run(ServiceRecord.java:1150)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.os.HandlerThread.run(HandlerThread.java:67)
at com.android.server.ServiceThread.run(ServiceThread.java:44)

(REDACTED) Failed to process cache entry for package(%s).
android.content.pm.PackageManager$NameNotFoundException: androidx.test.services
at android.app.ApplicationPackageManager.getInstallSourceInfo(ApplicationPackageManager.java:2541)
at com.google.android.apps.gsa.nga.engine.ag.ae.a(PG:13)
at com.google.android.libraries.gsa.k.a.j.call(PG:2)
at java.util.concurrent.FutureTask.run(FutureTask.java:264)
at com.google.common.util.concurrent.dq.run(PG:4)
at com.google.android.libraries.i.af.run(PG:1)
at com.google.android.libraries.i.an.run(PG:23)
at com.google.android.libraries.i.l.run(PG:2)
at com.google.android.libraries.i.q.run(PG:4)
at java.lang.Thread.run(Thread.java:1012)

@jBorkowska
Copy link
Collaborator

Could you post full log from the run? @cljobs

@jBorkowska
Copy link
Collaborator

jBorkowska commented Apr 9, 2025

Also I didn't reproduce the crash with getting this "FlutterError.onError override" so it must be something else

@jBorkowska jBorkowska added the waiting for response Waiting for user's response label Apr 9, 2025
@cljobs
Copy link

cljobs commented Apr 9, 2025

@jBorkowska
I typed Command patrol test --target integration_test/example_test.dart --flavor dev --device 'emulator-5554' --verbose

Terminal Log

result:

Unhandled exception:
FormatException: Missing extension byte (at offset 1757)
#0      _Utf8Decoder.convertChunked (dart:convert-patch/convert_patch.dart:1956:7)
#1      _Utf8ConversionSink.addSlice (dart:convert/string_conversion.dart:304:28)
#2      _Utf8ConversionSink.add (dart:convert/string_conversion.dart:300:5)
#3      _ConverterStreamEventSink.add (dart:convert/chunked_conversion.dart:69:18)
#4      _SinkTransformerStreamSubscription._handleData (dart:async/stream_transformers.dart:111:24)
#5      _RootZone.runUnaryGuarded (dart:async/zone.dart:1594:10)
#6      _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:365:11)
#7      _BufferingStreamSubscription._add (dart:async/stream_impl.dart:297:7)
#8      _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:784:19)
#9      _StreamController._add (dart:async/stream_controller.dart:658:7)
#10     _StreamController.add (dart:async/stream_controller.dart:606:5)
#11     _Socket._onData (dart:io-patch/socket_patch.dart:2455:41)
#12     _RootZone.runUnaryGuarded (dart:async/zone.dart:1594:10)
#13     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:365:11)
#14     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:297:7)
#15     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:784:19)
#16     _StreamController._add (dart:async/stream_controller.dart:658:7)
#17     _StreamController.add (dart:async/stream_controller.dart:606:5)
#18     new _RawSocket.<anonymous closure> (dart:io-patch/socket_patch.dart:1942:33)
#19     _NativeSocket.issueReadEvent.issue (dart:io-patch/socket_patch.dart:1385:14)
#20     _microtaskLoop (dart:async/schedule_microtask.dart:40:21)
#21     _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)
#22     _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:118:13)
#23     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:185:5)

@jBorkowska
Copy link
Collaborator

internal Server Error maybe #2268

From looking at your command I can tell that you don't run the same test twice, so it's not that one

The log you posted is not full logcat log from the test execution, only a part with an error. Unfortunately it's not enough information to know why it crashed. Please post whole log or provide a repository where I can reproduce the error (doesn't have to be your project, even better if it's just a sample project where this error occurs)

@jBorkowska
Copy link
Collaborator

@pdenert I think it's related to logs feature, we fixed similar one already but this is not the same (with too long logs bc of a native error)

@jBorkowska jBorkowska added waiting for response Waiting for user's response and removed waiting for response Waiting for user's response labels Apr 9, 2025
@cljobs
Copy link

cljobs commented Apr 9, 2025

maybe I found it..!

my project use Logger Package to Log Http Call.
I turn off Http Intercept, It succeed

@jpoh281
Copy link

jpoh281 commented Apr 9, 2025

This is my personal account.

During testing, I confirmed that this error occurs when trying to print the response body using the _printAll message within this section of the code: https://github.com/cfug/dio/blob/808f81b5920e0df3173ce836da340629385722f4/dio/lib/src/interceptors/log.dart#L121-L146

However, although I tried creating an example project, I couldn't determine the exact text that triggers the error exposure.

Is it possible to fix the problem where the CLI encounters issues when specific strings are received by modifying the patrol_cli library?

@jBorkowska
Copy link
Collaborator

I see. Maybe it's because the log is too long and CLI fails to print it - we had this problem before. I'll try to fix it on a branch so you can check if it helped

@jBorkowska jBorkowska removed the waiting for response Waiting for user's response label Apr 10, 2025
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

No branches or pull requests

8 participants