Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-35004

Android Emulator plugin fails to shutdown AVD since SDK emulator 25.1.6 release

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Critical Critical
    • None
    • Ubuntu 16.04 64bit
      Android SDK revision 25.1.6
      Jenkins 2.5 and 1.651.2
      Android Emulator Plugin 2.14.1

      Android Emulator plugin fails to correctly shutdown the emulator started for the test, but this fact is not logged in console output:

      [android] Starting Android emulator
      [android] Erasing existing emulator data...
      $ /var/lib/jenkins/tools/android-sdk/tools/emulator -engine classic -ports 5748,5749 -report-console tcp:5832,max=60 -prop persist.sys.language=en -prop persist.sys.country=US -avd hudson_en-US_160_HVGA_android-19 -no-snapshot-load -no-snapshot-save -wipe-data -no-window -no-audio -gpu off
      [android] Emulator reported that the console is available on port 5,748
      [android] Waiting for emulator to finish booting...
      $ /var/lib/jenkins/tools/android-sdk/platform-tools/adb -s emulator-5748 wait-for-device shell getprop init.svc.bootanim
      [android] Emulator reported that the startup process is 'stopped'
      $ /var/lib/jenkins/tools/android-sdk/platform-tools/adb -s emulator-5748 logcat -v time
      [android] Emulator is ready for use (took 23 seconds)
      [test2-maremoto-studio] $ /bin/sh -xe /tmp/hudson1987499027468087201.sh
      ...
      [android] Stopping Android emulator
      [android] Archiving emulator log
      $ /var/lib/jenkins/tools/android-sdk/platform-tools/adb kill-server
      Finished: SUCCESS
      

      This leads to

      1. emulator processes continue consuming CPU and RAM
      2. next emulator start fails due to resources remains locked
        [android] Starting Android emulator
        [android] Erasing existing emulator data...
        $ /var/lib/jenkins/tools/android-sdk/tools/emulator -engine classic -ports 5726,5727 -report-console tcp:5861,max=60 -prop persist.sys.language=en -prop persist.sys.country=US -avd hudson_en-US_160_HVGA_android-19 -no-snapshot-load -no-snapshot-save -wipe-data -no-window -no-audio -gpu off
        WARNING: SD Card image already in use: /var/lib/jenkins/.android/avd/hudson_en-US_160_HVGA_android-19.avd/sdcard.img
        ko:Snapshot storage already in use: /var/lib/jenkins/.android/avd/hudson_en-US_160_HVGA_android-19.avd/snapshots.img
        emulator: WARNING: Classic qemu does not support SMP. The hw.cpu.ncore option from your config file is ignored.
        emulator: WARNING: userdata image already in use, changes will not persist!
        
        emulator: WARNING: cache image already in use, changes will not persist!
        ...
        

      The root cause is Google emulator console behavior change: now you MUST authenticate in emulator console before you can issue 'kill' command. This change was introduced about a week ago when Android SDK 25.1.6 was released.

      But the Android Emulator plugin can't handle authentication required - it simply issues 'kill' command to the emulator console, and the emulator silently refuses this unauthorized command.

      Talking to emulators leaved running by plugin "by-hands" via telnet(1) - shutdowns them successfully:

      kaa@AGnb:~$ ps -augxw |grep ^jenkins |grep emulator
      jenkins  23511 15.2  4.4 1144460 333832 ?      Sl   12:12   0:34 /var/lib/jenkins/tools/android-sdk/tools/emulator64-x86 -engine classic -ports 5698,5699 -report-console tcp:5839,max=60 -prop persist.sys.language=en -prop persist.sys.country=US -avd hudson_en-US_160_HVGA_android-19 -no-snapshot-load -no-snapshot-save -wipe-data -no-window -no-audio -gpu off
      jenkins  23518  0.0  0.0      0     0 ?        Z    12:12   0:00 [emulator64-cras] <defunct>
      kaa@AGnb:~$ 
      
      kaa@AGnb:~$ sudo cat /var/lib/jenkins/.emulator_console_auth_token ; echo ""
      JDKCEhwZ6jhmnIV3
      kaa@AGnb:~$ 
      
      AGnb:~$ 
      kaa@AGnb:~$ telnet 127.1 5698
      Trying 127.0.0.1...
      Connected to 127.1.
      Escape character is '^]'.
      Android Console: Authentication required
      Android Console: type 'auth <auth_token>' to authenticate
      Android Console: you can find your <auth_token> in 
      '/var/lib/jenkins/.emulator_console_auth_token'
      OK
      help
      Android console command help:
      
          help|h|?         print a list of commands
          avd              control virtual device execution
          auth             user authentication for the emulator console
          quit|exit        quit control session
      
      try 'help <command>' for command-specific help
      OK
      avd name
      hudson_en-US_160_HVGA_android-19
      OK
      auth JDKCEhwZ6jhmnIV3
      Android Console: type 'help' for a list of commands
      OK
      help
      Android console command help:
      
          help|h|?         print a list of commands
          event            simulate hardware events
          geo              Geo-location commands
          gsm              GSM related commands
          cdma             CDMA related commands
          crash            crash the emulator instance
          kill             kill the emulator instance
          network          manage network settings
          power            power related commands
          quit|exit        quit control session
          redir            manage port redirections
          sms              SMS related commands
          avd              control virtual device execution
          qemu             QEMU-specific commands
          sensor           manage emulator sensors
          finger           manage emulator finger print
      
      try 'help <command>' for command-specific help
      OK
      kill
      OK: killing emulator, bye bye
      Connection closed by foreign host.
      kaa@AGnb:~$ ps -augxw |grep ^jenkins |grep emulator
      kaa@AGnb:~$ 
      

      As I can see, lines 584-586 of "src/main/java/hudson/plugins/android_emulator/AndroidEmulator.java" must be patched to issue 'auth' command before 'kill'

              // Stop emulator process
              log(emu.logger(), Messages.STOPPING_EMULATOR());
              boolean killed = emu.sendCommand("kill");
      

            orrc Christopher Orr
            kaa Andrey Kopeyko
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: