Detox: Wont Launch Valid Android Emulator AVD

Created on 14 Feb 2019  路  17Comments  路  Source: wix/Detox

Description

The detox test command fails with the error message "Error: Emulator with name has a corrupt config.ini file (/path/to/config.ini), try fixing it by recreating an emulator.

This happens for a perfectly valid emulator avd that starts up without problem. In my particular case the avd was created from the command line using the avdmanager.bat create avd command.

Looking through the source code, this error is thrown from EmulatorDriver.js _fixEmulatorConfigIniSkinName(..) when the config.ini file for the emulator does not have a 'skin.name' value and does not have hw.lc.width and hw.lcd.height values.

It is unclear why the emulator driver is trying to fix the config.ini in this way. Ideally the command should work for such an emulator avd since the avdmanager does not create it with those values and the avd works without them.

If there is a specific scenario where this behavior is required or it is a requirement specific to detox then, at a minimum, the error message should be made more descriptive to provide a clear solution. Such as instructing the user that skin and/or height + width specification is required in the config.ini.

Steps to Reproduce

Run the detox test -c <config> command. Use a configuration of type android.emulator and select an avd name with a config.ini file that has neither the skin.name property nor the hw.lcd.width / hw.lcd.height properties.

Detox, Node, Device, Xcode and macOS Versions

  • Detox: 10.0.7
  • React Native: 0.57.8
  • Node: 11.6.0
  • Device: Android Emulator
  • Xcode: N/A
  • macOS: N/A
  • Windows: Windows 10 Pro v1703

Device and verbose Detox logs

detox[716] INFO:  [DetoxServer.js] server listening on localhost:50369...
detox[716] DEBUG: [AsyncWebSocket.js/WEBSOCKET_OPEN] opened web socket to: ws://localhost:50369
detox[716] TRACE: [AsyncWebSocket.js/WEBSOCKET_SEND] {"type":"login","params":{"sessionId":"3a17d4e8-c480-0900-5910-4068d33e6274","role":"tester"},"messageId":0}
detox[716] DEBUG: [DetoxServer.js/LOGIN] role=tester, sessionId=3a17d4e8-c480-0900-5910-4068d33e6274
detox[716] DEBUG: [DetoxServer.js/LOGIN_SUCCESS] role=tester, sessionId=3a17d4e8-c480-0900-5910-4068d33e6274
detox[716] TRACE: [AsyncWebSocket.js/WEBSOCKET_MESSAGE] {"type":"loginSuccess","params":{"sessionId":"3a17d4e8-c480-0900-5910-4068d33e6274","role":"tester"},"messageId":0}

detox[716] DEBUG: [exec.js/EXEC_CMD, #0] C:\path\to\emulator -list-avds --verbose
detox[716] TRACE: [exec.js/EXEC_SUCCESS, #0] <avd name>

detox[716] ERROR: [index.js/DETOX_INIT_ERROR] Error: Emulator with name <emulator name> has a corrupt config.ini file (C:\path\to/<avd name>.avd/config.ini), try fixing it by recreating an emulator.
    at EmulatorDriver._fixEmulatorConfigIniSkinName (C:\path\to\EmulatorDriver.js:30:15)
    at EmulatorDriver.acquireFreeDevice (C:\path\to\EmulatorDriver.js:91:16)
    at process.internalTickCallback (internal/process/next_tick.js:77:7)
acceptebug looking for contributors android 馃搶 pinned

All 17 comments

I do have same problem. Is there any solution for this?
(OR)
Just provide the info how to deal with android emulator on CI

detox[26902] ERROR: [index.js/DETOX_INIT_ERROR]
Error: Emulator with name Nexus_6_API_26 has a corrupt config.ini file (/root/.android/avd/Nexus_6_API_26.avd/config.ini), try fixing it by recreating an emulator.
at EmulatorDriver._fixEmulatorConfigIniSkinName (/bitrise/src/node_modules/detox/src/devices/drivers/EmulatorDriver.js:30:15)
at EmulatorDriver.acquireFreeDevice (/bitrise/src/node_modules/detox/src/devices/drivers/EmulatorDriver.js:91:16)
at
at process._tickCallback (internal/process/next_tick.js:188:7)
detox[26902] DEBUG: [DetoxServer.js/DISCONNECT] role=tester, sessionId=dca0dbbd-9e47-d712-47f4-b15b3f063780
detox[26902] ERROR: [EmulatorTelnet.js/TELNET_ERROR]
err: Error: connect ECONNREFUSED 127.0.0.1:23
at Object._errnoException (util.js:1022:11)
at _exceptionWithHostPort (util.js:1044:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1198:14)

@ravi-ts As a workaround you can manually browser to where your emulator config.ini is and put in explicit values for hw.lc.width and hw.lcd.height. This should solve the emulator startup problem.

You mean emulator -avd Nexus_6_API_26 -skin 768x1280 -no-window -no-audio -debug-init > /dev/null 2>&1 & like this on bitrise?

I'm not sure that will solve the problem. I believe -skin just tells the emulator command to ignore the value (if any) in the config.ini and use the value you specify instead. The detox code is actually inspecting the config.ini and looking for the 'skin.name' value.

https://github.com/wix/Detox/blob/e7cbb696d7f8a1beff3ac50e319dbcca1aa2b60e/detox/src/devices/drivers/EmulatorDriver.js#L25

If bitrise gives you access to setup / customize your emulator configs then you need to add the values I provide into the config ini:

/root/.android/avd/Nexus_6_API_26.avd/config.ini

If bitrise doesn't provide that option then I can't think of any way to work around the problem. You'll most likely have to patch the detox behavior yourself or wait until a fix is available.

Thanks Ryan,

I will check any possibilities.

@ravi-ts I am also experiencing this problem on bitrise. Any update on a possible solution?

Short answer is Not yet,

I tried many ways to install emulator with appropriate hardware configurations and I didn't succeed yet.

If I try in my Mac machine I can see .android/XXXX.avd/config.ini with all necessary parameters but on linux machine I didn't find it.

On the linux machine see if there is an ANDRDOID_AVD_HOME environment variable set (different than the ANDROID_HOME variable). The avd manager and emulator commands should put the AVD files in the directory for that variable. If not, then see if there is an ANDROID_SDK_HOME env variable with a .android/ folder in it.

If neither are defined and you can't find the location, you can try setting the ANDROID_AVD_HOME environment variable yourself to control the directory (either setting the env variable persistently or on a session by session basis)

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If you believe the issue is still relevant, please test on the latest Detox and report back.
Thank you for your contributions.

The issue has been closed for inactivity.

The original issue was with emulators created with avdmanager create avd and launched through CLI, not Android Studio (issue described here https://stackoverflow.com/a/47265664/930391).

I am not sure Google has solved the issue, last time I tried this, about 6 months ago, the issue was still present on macOS. Either if its solved or not in newer version, I'd rather keep this piece of code to support older SDK versions. Let's find a better solution together, but I need to understand:

How your emulators were created (cli, Android Studio?)
How the config.ini looks like (paste it if you can please)
How are you launching the emulator? (With Detox? from Android Studio?)

@RyanThomas73 I tried out your setup from https://github.com/wix/Detox/pull/1504#issuecomment-508450261 and the emulator launched was actually usable (low res, but nothing looked broken).
This is great! Though I wouldn't want to remove this piece of code just yet, it needs some transition time because it solves an issue on some emulators.
Ideally, I would like to understand when (on what avdmanager/emulator version) this was fixed, so we can add a condition in code to only fix that for the older binary versions.

I'm using Android emulator version 29.0.11.0 (build_id 5598178) (CL:N/A)

I'm also having this issue locally when i try to first download, create, and run.

$ANDROID_HOME/tools/bin/sdkmanager "system-images;android-28;google_apis_playstore;x86"
echo yes | $ANDROID_HOME/tools/bin/sdkmanager --licenses
echo no | $ANDROID_HOME/tools/bin/avdmanager create avd --force --name Nexus_5X_API_28 --abi google_apis_playstore/x86 --package 'system-images;android-28;google_apis_playstore;x86'

i'll first get Emulator with name Nexus_5X_API_28 has a corrupt config.ini file

to which i append:

echo 'hw.lcd.height = 1920' >> $HOME/.android/avd/Nexus_5X_API_28.avd/config.ini
echo 'hw.lc.width = 1080' >> $HOME/.android/avd/Nexus_5X_API_28.avd/config.
echo 'hw.lcd.density = 161' >> $HOME/.android/avd/Nexus_5X_API_28.avd/config.ini

.. same complaint, so i add skin:

echo 'skin.name=Nexus_5X_API_28' >> $HOME/.android/avd/Nexus_5X_API_28.avd/config.ini

and now i get:

emulator: ERROR: unknown skin name 'Nexus_5X_API_28'

appending this got rid of that error:

echo 'skin.path = $ANDROID_HOME/skins/nexus_5'

now off to other android e2e issues...

lots of idling:

10-08 15:29:19.519  3515  3515 W UiControllerImpl: Waiting for: ASYNC_TASKS_HAVE_IDLED for 6300 iterations.
10-08 15:29:20.157  1876  3489 I GnssLocationProvider: WakeLock acquired by sendMessage(REPORT_SV_STATUS, 0, com.android.server.location.GnssLocationProvider$SvStatusInfo@ca7c0c4)
10-08 15:29:20.157  1876  1890 I GnssLocationProvider: WakeLock released by handleMessage(REPORT_SV_STATUS, 0, com.android.server.location.GnssLocationProvider$SvStatusInfo@ca7c0c4)

hi @jeremyeaton89 could you provide the full script? because i still got the same error. does the sequence matter? is it before or after create avd?

I added

script:
  - printf "\nhw.lcd.height=1920\nhw.lcd.width=1080\nhw.lcd.density=161\nskin.name=240x426" >> /home/travis/.android/avd/Pixel_API_28_AOSP.avd/config.ini

to my travis config and I think it did the trick

All, please retry using Detox 16.0.2 - we've restricted the skin patching to older emu's.

Was this page helpful?
0 / 5 - 0 ratings