Nativescript-cli: Stuck on starting emulator on Android

Created on 9 Nov 2016  路  17Comments  路  Source: NativeScript/nativescript-cli

Issue

I have noticed that from time to time when trying to "run" an {N} application on Android via tns emulate android the terminal gets stuck after:

Starting Android emulator with image Nexus_5X_API_24

and after a flew minutes this error is shown:

Cannot run your app in the native emulator. Increase the timeout of the operation with the --timeout option or try to restart your adb server with 'adb kill-server' command. Alternatively, run the Android Virtual Device manager and increase the allocated RAM for the virtual device.

Doing the mentioned adb kill-server or timeout increasing does not resolve the issue.

Workaround

Manually start the Android emulator via Android Studio and use tns run android

bug low

All 17 comments

Another work around:
tns run android --timeout 300
tns run android --avd Name-of-some-faster-emulator

@dtopuzov None of those workarounds work for me on my end. The same message is written to the terminal:

$ tns run android --timeout 300
Starting Android emulator with image Nexus_5X_API_24

or

$ tns run android --avd Nexus_5X_API_24
Starting Android emulator with image Nexus_5X_API_24

Doing the same commands with a API 23 level emulator is ok, but CLI defaults to API 24 level.

CLI defaults to latest installed and booting of Api24 is significantly slower compared to Api23.

Maybe we can improve upon this by giving access to changing what CLI uses as default emulator.

@VladimirAmiorkov you can pass --avd <name of emulator> - this way CLI will use it instead :)

@rosen-vladimirov Yes this is a good option to have but I do not think it should be considered a "goto" solution for this issue as it is not a visible option that many users will not know that exists or know how to search for such option (maybe add it somewhere in the docs). What I am talking about is as CLI currently will use the latest emulator available which may cause all kinds of issues (like this one), it would be great if the users can change what CLI will use when executing tns emulate android (without additional options).

I'm with @rosen-vladimirov, the default should use the newest emulator installed. We have a way for the user to use a different emulator using --device flag, and this flag is described in the help of the tns emulate command.

@Plamen5kov Hmm, well that is absolutely true but the fact is that the goto and simplest command tns emulate android does not work on my end at all making it useless. Having to write and remember the full name of the device when simply wanting to start an {N} app is lets say inconvenient at the very least. I am hoping we can do better for our default command.

@VladimirAmiorkov I could understand the logic behind the user choosing what emulator to be started as a default behavior, but if all of the given options get stuck we still won't have an answer to the real problem. That's why i believe, it's best to focus on the problem of why it's stuck and fix it. After we've fixed the major problem, we can have a discussion of what will the best user experience be.

@Plamen5kov Yes of course, finding the source and possibly fixing it so that the execution is not getting stuck is the first concern that should be taken into account. Adding a way to change the default device was as mentioned earlier nothing more than a improvement suggestion rather than a fix for this issue.

@VladimirAmiorkov is there a way to reproduce this problem or does it happen for random emulators on random API levels?

It happen always when emulator is not started before tns run android and emulator startup time is slower than 2 minutes (which happens with arm emulators or latest api levels or slow desktop machines).

Steps to reproduce:

tns run android --avd Name-of-some-very-slow-arm-emulator

Note: Currently tns run android -avd <emulator name> is broken in @next, but can try with latest official release.

btw, the error message is correct:

Cannot run your app in the native emulator. Increase the timeout of the operation with the --timeout option or try to restart your adb server with 'adb kill-server' command. Alternatively, run the Android Virtual Device manager and increase the allocated RAM for the virtual device.

What we can do is may be increase default timeout a little bit.

Closing this, since the original issue has a solution we've provided which is --timeout. Furthermore, we plan on deprecating and removing the emulate command.

@Plamen5kov This issue occurs to me even for tns run android and tns debug android. I am using 3.4.0 nativescript version.

Hi @kamlekar, could you open a new issue, following the issue template so we can help you resolve your issue faster.
Please include the emulator version and type.

Ok will do. Thanks for quick reply.

Was this page helpful?
0 / 5 - 0 ratings