Top Level Namespace
Defined Under Namespace
Modules: Motion
Instance Method Summary collapse
- #available_avds ⇒ Object
- #define_rake_tasks(data) ⇒ Object
-
#emulator_path ⇒ Object
adb_path is provided by the android template.
- #ensure_emulator_running ⇒ Object
- #invoke_rake(platform, task) ⇒ Object
- #running_emulator_id ⇒ Object
Instance Method Details
#available_avds ⇒ Object
27 28 29 |
# File 'lib/motion-cross-platform/setup_android.rb', line 27 def available_avds `"#{emulator_path}" -list-avds 2>/dev/null`.strip.split("\n").reject(&:empty?) end |
#define_rake_tasks(data) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/motion-cross-platform/helpers.rb', line 3 def define_rake_tasks(data) data.each do |platform, tasks| namespace platform do tasks.each do |name, description| desc description task name do invoke_rake platform, name end end end end end |
#emulator_path ⇒ Object
adb_path is provided by the android template.
23 24 25 |
# File 'lib/motion-cross-platform/setup_android.rb', line 23 def emulator_path "#{App.config.sdk_path}/emulator/emulator" end |
#ensure_emulator_running ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/motion-cross-platform/setup_android.rb', line 41 def ensure_emulator_running if running_emulator_id App.info "Emulate", "Emulator is already running" return end avds = available_avds if avds.empty? App.fail "No emulators found. Create one with Android Studio or `avdmanager`." end avd_name = avds.first App.info "Emulate", "Starting emulator \"#{avd_name}\"..." # Start emulator in background Process.detach(spawn(emulator_path, "-avd", avd_name, [:out, :err] => "/dev/null")) # Wait for emulator to be ready App.info "Emulate", "Waiting for emulator to boot..." timeout = 120 # seconds start_time = Time.now loop do if Time.now - start_time > timeout App.fail "Emulator failed to start within #{timeout} seconds" end if running_emulator_id boot_completed = `"#{adb_path}" -e shell getprop sys.boot_completed 2>/dev/null`.strip if boot_completed == "1" break end end sleep 2 end end |
#invoke_rake(platform, task) ⇒ Object
16 17 18 19 |
# File 'lib/motion-cross-platform/helpers.rb', line 16 def invoke_rake(platform, task) trace = Rake.application..trace == true system "platform=#{platform} bundle exec rake \"#{task}\" #{trace ? "--trace" : ""}" or exit 1 end |
#running_emulator_id ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/motion-cross-platform/setup_android.rb', line 31 def running_emulator_id output = `"#{adb_path}" -e devices 2>/dev/null` # Parse output to find emulator device (e.g., "emulator-5554") output.lines.drop(1).each do |line| device = line.split.first return device if device && device.start_with?("emulator-") end nil end |