-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
detox test hangs when starting the Android emulator (Apple Silicon) #2772
Comments
Hey @drash-course,
in both cases, try to run |
2a. Emulator launches but does not appear in
Here are the emulator logs. fleetback-ci@fleetback-ci-mini ~ % /Users/fleetback-ci/Library/Android/sdk/emulator/emulator -verbose -no-audio -no-boot-anim -port 15776 @Pixel_4_API_Semulator: Android emulator version 30.3.5.0 (build_id 7036990) (CL:N/A) emulator: emuDirName: '/Users/fleetback-ci/Library/Android/sdk/emulator' emulator: VM heap size 1000MB is above maximum supported 576MB, setting it to that value emulator: VERBOSE: FeatureControlImpl.cpp:175: Unexpected feature list: emulator: VERBOSE: FeatureControlImpl.cpp:177: VirtconsoleLogcat emulator: found magic skin width=1080 height=2280 bpp=16 emulator: registered 'boot-properties' qemud service emulator: Starting QEMU main loop emulator: emulator_window_fb_rotate emulator: VERBOSE: MultiDisplay.cpp:695: config multidisplay with config.ini 0x0 0x0 0x0
emulator: _hwFingerprint_connect: connect finger print listen is called emulator: got message from guest system fingerprint HAL emulator: INFO: boot completed emulator: ERROR: AdbHostServer.cpp:102: Unable to connect to adb daemon on port: 5037 2b. Emulator launches and
Here are the emulator logs. fleetback-ci@fleetback-ci-mini ~ % /Users/fleetback-ci/Library/Android/sdk/emulator/emulator -verbose -no-audio -no-boot-anim @Pixel_4_API_Semulator: Android emulator version 30.3.5.0 (build_id 7036990) (CL:N/A) emulator: emuDirName: '/Users/fleetback-ci/Library/Android/sdk/emulator' emulator: VM heap size 1000MB is above maximum supported 576MB, setting it to that value emulator: VERBOSE: FeatureControlImpl.cpp:175: Unexpected feature list: emulator: VERBOSE: FeatureControlImpl.cpp:177: VirtconsoleLogcat emulator: found magic skin width=1080 height=2280 bpp=16 emulator: registered 'boot-properties' qemud service emulator: Starting QEMU main loop emulator: INFO: GrpcServices.cpp:288: Started GRPC server at 127.0.0.1:8554, security: Local emulator: VERBOSE: MultiDisplay.cpp:695: config multidisplay with config.ini 0x0 0x0 0x0 emulator: got message from guest system fingerprint HAL emulator: INFO: boot completed |
There is an update for the emulator. I'll try again with version 30.6.5. |
So looks like we're both charting new territories 😄
|
|
Kudos!!! Does this work with Detox, then? |
Yes it works! Here are my steps if someone gets the same problem:
The google_apis image was not working for me, from the
On the detox side, maybe it's a regression but I had to run adb reverse. I'll make another ticket if I can reproduce. |
I found this to download Android Studio 4.1.2. The page title is wrong though, it does download 4.1.2 and not 4.1.3. |
You can invoke port reversing through Detox as well. As for Android Studio versions, I recommend to try to look up a Google archive. |
Indeed, here is my const {
DetoxCircusEnvironment,
SpecReporter,
WorkerAssignReporter,
} = require('detox/runners/jest-circus');
const TWENTY_MINUTES = 20 * 60 * 1000;
class CustomDetoxEnvironment extends DetoxCircusEnvironment {
constructor(config, context) {
super(config, context);
this.initTimeout = TWENTY_MINUTES;
this.registerListeners({ SpecReporter, WorkerAssignReporter });
}
async initDetox() {
const instance = await this.detox.init(undefined, { launchApp: false });
await instance.device.reverseTcpPort(8081); // added this line
await instance.device.launchApp({ permissions: { notifications: 'YES', camera: 'YES', microphone: 'YES', photos: 'YES' } });
return instance;
}
} |
This may be off-topic. If you use
Note that
You should now uninstall it from brew to avoid having multiple
|
@drash-course I would advise against that. |
Not sure if this will be useful for others or not, but as of today (July 15, 2021) a procedure that worked for me to get Detox tests working for react-native on an Apple M1 device were:
I believe most of this is simply confirming the above info, but an important point for me was total emulator network failure on API31 while API30 worked in general but did need the manual reverse port mapping. Cheers |
@mikehardy Thanks!!! |
Oh yes! If you have the bundle packed up in the app (release mode) of course, it doesn't have to go over the port to fetch - good extra detail. This arm64 stuff is still pretty fiddly but at least most things are possible now. Side note: just last week google finally published a .xcframework with arm64 emulator slice for google sign in. Maps still doesn't work AFAIK. So, the whole ecosystem is still fractured after this architecture earthquake. But my detox tests ran! :-). Cheers |
... which makes it all the more astounding. Kudos! |
Hey I'm struggling with this issue myself we get the following message:
but then most of the times it actually continues with the tests. The main issue I have is that it's a bit unreliable and also hangs for 2 minutes before continuing (I think it keeps retrying or something). I think it would be good to reopen this issue until a stable solution is out there, that would make it easier for folks like me to find a place they can wait for better news. |
I have found emulator startup to be unreliable for android emulators forever, intel macs as well. I use a kill / retry loop for my CI for this reason. Once booted, this failure to detect emulator problem should only be warning + delay though, I had 100% reliable test execution even with that warning given I already had an emulator successfully booted. |
@mikehardy could you share with me your |
Check react-native-firebase e2e workflow for android |
@mikehardy would you not rather let Detox spin up the emulators for ya? |
Too flaky in practice. The first restart hits maybe 10% of the time in github actions, second maybe 1% and so on. That's intolerable and I don't think detox has emu restart logic? If it does and I missed it though then sure |
I finally cracked it. I was starting the emulator but then detox was also trying to start it and sometimes this caused errors in connection to it. As a solution, I made sure the launch args are identical in both cases (detox and my own launch). The most important one was to add the port option so I ensure that both will try to create it in the same port, otherwise, I could end up with 2 instances (not very often). @d4vidi I wonder if there's a way to skip the device launch altogether and just skip straight to the install? When trying to connect and failing it will spend 2 mins. If I could skip this step this would improve my tests considerably. |
In my experience if Detox detects the emulator/simulator is already up, it will not attempt to boot it, it just installs. So we boot separately (with flaky-restart-logic as above) and detox handles it. But locally (dev machines, where it's faster etc) detox boots things for me the first time in the morning according to the AVD name (android) or simulator profile (iOS) specified in detox config. |
@sorodrigo, @mikehardy is right. I don't understand where this emulator boot-up race comes from but it sounds unhealthy. Technically, Detox enables you to preboot the emulator yourself. If it's an instance of the AVD specified in Detox's config of choice, then Detox should choose it for test execution. |
@d4vidi maybe then we just need to opt out of patching the emulator? Detox tries to patch it and it takes 2 min to fail and continue with the tests |
@sorodrigo what's you execution environment? Strikes me odd that the emulator binary is not found. |
We're running the e2e in mac M1 machines using macOS Catalina. Detox version 17, because the latest version fails in M1 and also our testing code does not work well with the new version in other machines. |
I am only chiming in quickly to say this is an interesting coincidence! react-native-firebase, which is my M1 detox experience at the moment, is also stuck on Detox 17. I didn't think to mention it before, but anything I mentioned up above about it working on M1 was validated on Detox 17 and if 18 is broken I'm unaware of it and haven't tried yet |
@mikehardy that's actually very important input. Obviously, we urge you'd at all times use the latest (and greatest) of Detox (i.e. version 18+). |
Indeed - recognizing this is now veering off topic, our being on v17 vs v18 is totally on me/us over at react-native-firebase (though I do have great success on M1 with detox v17). I have moving to current stable as a todo for me and for whatever it's worth we just did a competitive analysis of the various test platforms for our next generation e2e harnesses (to be used in react-native-firebase, react-native-google-ads, notifee, react-native-mlkit, etc) and we're re-committing to Detox after a brief Cavy dalliance, so rest assured if v18 of Detox has an M1 problem I'll be back here, but hopefully with a PR :-). Cheers |
@sorodrigo not sure what parts of Detox you're using but I've updated to Detox v18 now and it works fine on M1, just not on iOS15 (a known issue #2895). I also tested Detox v18 with Android 12 and it appears fine (#2899). As far as I can tell, the only thing not working at the moment is ios15 (noted) and maybe a need for a manual adb reverse for bundler port 8081 - cheers |
Thrilled to know! Looking forward to getting feedback on v18. |
For me as @mikehardy mentioned above, a
|
""/Users/it062305/Library/Android/sdk/platform-tools/adb" -s emulator-11374 shell "ps | grep "com.eroev.app$""" failed with error = ChildProcessError: Command failed: "/Users/it062305/Library/Android/sdk/platform-tools/adb" -s emulator-11374 shell "ps | grep "com.eroev.app$"" |
Describe the bug
We upgraded our Detox machine to the new M1 Mac mini and ran into this issue.
detox build -c android.emu.debug
succeeds without problems.detox test -c android.emu.debug
starts but then hangs when the emulator window opens. The app does not launch. Here is the printout.Building and running the iOS tests works. Both iOS and Android tests build, run and pass on our Intel MacBooks. I had to patch line 22 of EmulatorVersionResolver.js because the command seems broken but still prints the version so it's easy to workaround.
If you Cmd+Q the emulator, more logs appear. The whole logs are attached to the post.
If you don't have a M1 Mac to reproduce the problem, can you give us some pointers as to why the process can get stuck on the adb command? We can help debug and fix the problem.
Steps To Reproduce
rawOutput = await (this._emulatorExec.exec(new QueryVersionCommand()).catch(e => e.stdout || e.stderr)) || '';
detox build -c android.emu.debug && detox test -c android.emu.debug
Expected behavior
It should launch the app and run the tests.
Detox Trace-Logs
See attached file detox_bug.txt
Device logs (adb logcat)
It says
- waiting for device -
and nothing happens. If you need them I can try with Android Studio.Environment (please complete the following information):
The text was updated successfully, but these errors were encountered: