apache / cordova-android

Apache Cordova Android
https://cordova.apache.org/
Apache License 2.0
3.59k stars 1.52k forks source link

'cordova run android --emulator' command line tool stuck at 'Waiting for emulator to start...' #698

Closed tonetechnician closed 3 years ago

tonetechnician commented 5 years ago

OS: Windows 10 Cordova: 9.0.0 ADB: Android Debug Bridge version 1.0.40, Version 28.0.2-5303910 Emulator API version: Oreo | 27 | x86 | Android 8.1 (Google APIs)

I've installed cordova and am using it to develop an android app. I have all the SDK tools installed.

I'm running into an issue where I cannot start the emulator form the command line. I see there are a lot of posts about this already, but none really answer the problem or include verbose command line output.

Here is the command line output from the command cordova run android --emulator --verbose. I call this command from the /platforms/android/ directory in my project.

Waiting for emulator to start...
Running adb shell command "getprop dev.bootcomplete" on target emulator-5584...
Running command: adb -s emulator-5584 shell getprop dev.bootcomplete
Command finished with error code 1: adb -s,emulator-5584,shell,getprop,dev.bootcomplete
Running adb shell command "getprop dev.bootcomplete" on target emulator-5584...
Running command: adb -s emulator-5584 shell getprop dev.bootcomplete
Command finished with error code 1: adb -s,emulator-5584,shell,getprop,dev.bootcomplete
Running adb shell command "getprop dev.bootcomplete" on target emulator-5584...
Running command: adb -s emulator-5584 shell getprop dev.bootcomplete
Command finished with error code 1: adb -s,emulator-5584,shell,getprop,dev.bootcomplete

And then it just keeps looping.. So it seems it be an issue with cordova running the adb command. I'm not 100% sure what the steps would be to fix this.

Current Workaround

I have a workaround that just requires me to run the emulator from the Android Studio AVD Manager and then run

cordova emulate android 

which runs the app on the emulator.

I'd like to get the command line tool working because it will speed up my productivity.

Any help would be greatly appreciated!

janpio commented 5 years ago

I can confirm this is broken.

In my case it seems to have started after I upgraded my SDK Tools "Android Emulator" component to 29.0.9. (But not 100% sure to be honest): image What version are you having here @tonetechnician @lfwells @njoydrama @nitrotm?

I can also confirm that the workaround using AVD Manager of Android Studio to start the emulator, then using cordova emulate android works.

nitrotm commented 5 years ago

After updating to emulator 29.0.9 and tools 28.0.3 the issue is now gone for me. Also I found issues with older android images. I am using oreo with success.

janpio commented 5 years ago

Updating to Android SDK Platform-Tools (revision: 28.0.3) didn't do anything for me :/

nitrotm commented 5 years ago

And you are using cordova cli v9?

janpio commented 5 years ago

Yes. Cordova CLI 9, Cordova Android 8.0.0. Let's wait if the others that responded here can fix their issue by updating the SDK Platform-Tools.

njoydrama commented 5 years ago

The version I use is below. Cordova CLI 9 Cordova Android 8.1.0-nightly.2019.3.31.9531dbbc Android Emulator 28.0.25 Android SDK Platform-Tools 28.0.2 Intel x86 Emulator Accelerator(HAXM installer) 7.3.2 Emulated Performance Setting for AVD :

in my case, I did the following and the problem disappeared. But I don't know if this has any obvious effect.

  1. connect pc with real android phone and run cordova.("cordova run android"). i use galaxy note5.
  2. disconnect the phone and type "cordova run android" for run avd.
  3. avd run successful.

yeah, it just plug and play. but hope this will help.

misterzik commented 4 years ago

ionic

Same issue here after updating last night to 29.0.9, I am running cordova utilizing ionic, it was working just fine two days ago.

Anybody got a fix for this? 👍

breautek commented 4 years ago

I just seen this issue trying to use the emulator. Closing it and opening it did not fix it, however restarting the emulator by using the emulator power option to actually "shut down" android did fix it for me.

I'm not sure the exact cause of it, but I usually close the emulator without actually shutting it down, so perhaps it has something to do with that.

chenjuneking commented 4 years ago

power off the emulator, and Quit the emulator by hit Cmd + q on macOS, after that run cordova emulate android. this work for me.

pehagg commented 4 years ago

I'm on mac, the only way I can work around the issue is by starting the emulator using -no-snapshot. Alternatively, if you use Android Studio, doing a AVD device cold reboot should do the trick as well.

breautek commented 4 years ago

I have ran into this issue as well, rebooting the emulator device does fix it for me temporarily. I think it usually occurs if you close the emulator without actually powering it off, but it has also triggered after the emulator has been running for some time.

Next time I run into this issue, I'll see if the issue persists if I manually run the adb commands. It could be an adb bug.

I am using the latest sdk & platform tools and the issue still does occur occasionally for me.

pcwSlide commented 4 years ago

Mine came good - works well now - will start the AVD from cold - just got the latest updates..Seems to me the Cordova guys are just chasing the Addroid changes..

breautek commented 3 years ago

A bit more information n this issue.

Cordova repeately does ps command in the adb shell

https://github.com/apache/cordova-android/blob/e86b211cd18e3df1932a970d2f431b208a98ae42/bin/templates/cordova/lib/emulator.js#L356

And looks for android.process.acore. On a fresh boot of the emulator running ps command on the emulator I clearly see this process. Over time however ps returns:

generic_x86_arm:/ $ ps
USER            PID   PPID     VSZ    RSS WCHAN            ADDR S NAME                       
shell          5113  25902   12176   3848 0                   0 R ps
shell         25902    386   12932   3124 __ia32_co+          0 S sh

Even ps -A to return all processes, including processes owned by root fails to have android.process.acore listed.

Further research shows that android.proces.acore is a process responsible for android's ContactsProvider system.

I don't believe scanning for the android.process.acore is a reliable way to determine if the system is booted. It looks like it works on cold boots, but eventually the process is killed (probably when it isn't being used). Despite it's name, it has nothing to do with it being an android core (which I think was probably what the original author of the cordova codebase thought, with no blame... I'd would come to the same conclusion myself...)

Unfortunately it seems to be very difficult to determine if the emulator is ready to be used.

get prop sys.boot_completed appears to be one approach, but not all simulators use it (according to SO comments). Personally if android simulators (from what google provides) from android 5.1 to latest (ie the android versions cordova-android@9 will support) all supports sys.boot_completed prop, I think that is our best path forward.

pcwSlide commented 3 years ago

Thanks for your reseach - as a user I just find it frustrating that it keeps getting broken - as I say I am sure it is because of lack of information from the developers.. Currently I have to start an AVD - then cordova sees it.. I hope someone fxes it.. P -

breautek commented 3 years ago

I've been running into this issue about every 20 minutes... I have my local copy usng sys.boot_completed for now.

Later tonight I'll test the sys.boot_completed prop on each simulator provided by the android sdk. If that prop exists on each simulator, I'll make a PR.

pcwSlide commented 3 years ago

Cheers,

I can’t believe this is not a bigger issue..

Phil

From: Norman Breau notifications@github.com Sent: Friday, 22 May 2020 9:54 AM To: apache/cordova-android cordova-android@noreply.github.com Cc: pcwSlide pcw@winshop.com.au; Comment comment@noreply.github.com Subject: Re: [apache/cordova-android] 'cordova run android --emulator' command line tool stuck at 'Waiting for emulator to start...' (#698)

I've been running into this issue about every 20 minutes... I have my local copy usng sys.boot_completed for now.

Later tonight I'll test the sys.boot_completed prop on each simulator provided by the android sdk. If that prop exists on each simulator, I'll make a PR.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/apache/cordova-android/issues/698#issuecomment-632403298 , or unsubscribe https://github.com/notifications/unsubscribe-auth/ABFTBHVK5A6DQEPI2PGQPDDRSW5IPANCNFSM4HBLPEJQ . https://github.com/notifications/beacon/ABFTBHS7ULUZAF5YXFFJ77LRSW5IPA5CNFSM4HBLPEJ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEWY3KYQ.gif

kristofvdj88 commented 3 years ago

I also run into this issue several times a day. I can always resolve it just by opening another app on the emulator, like for instance the call app...

After doing that, the APK is magically installed and my app starts.

pcwSlide commented 3 years ago

Yes - if you open an AVD it will find it - but really - this should be fixed..

pcwSlide commented 3 years ago

Hey Guys - is this still not working? seems so..

breautek commented 3 years ago

This should be fixed in cordova-android@9.0.0 by https://github.com/apache/cordova-android/pull/978

If it's not working on cordova-android@9 then I would recommend opening a new ticket so that we can track it. You can reference this issue for context, but please still fill out the entire issue form.

Additional useful information to include in said bug report would be the output of the boot variable. You can find this by up the android shell (execute adb shell should put you into the android shell) and then provide the output of:

getprop sys.boot_completed

Do this when the emulator is in an error state where the cordova tooling is waiting forever. You should also include what emulator you're using.

Thanks, Norman