lib/ruboto/util/emulator.rb in ruboto-1.0.3 vs lib/ruboto/util/emulator.rb in ruboto-1.1.0

- old
+ new

@@ -9,11 +9,11 @@ def sdk_level_name(sdk_level) Ruboto::SdkVersions::API_LEVEL_TO_VERSION[sdk_level] || "api_#{sdk_level}" end - def start_emulator(sdk_level) + def start_emulator(sdk_level, no_snapshot) sdk_level = sdk_level.gsub(/^android-/, '').to_i STDOUT.sync = true if RbConfig::CONFIG['host_cpu'] == 'x86_64' if ON_MAC_OS_X emulator_cmd = '-m "emulator64-(arm|x86)"' @@ -22,15 +22,10 @@ end else emulator_cmd = 'emulator-arm' end - emulator_opts = '-partition-size 256' - if !ON_MAC_OS_X && !ON_WINDOWS && ENV['DISPLAY'].nil? - emulator_opts << ' -no-window -no-audio' - end - avd_name = "Android_#{sdk_level_name(sdk_level)}" new_snapshot = false if `adb devices` =~ /emulator-5554/ t = Net::Telnet.new('Host' => 'localhost', 'Port' => 5554, 'Prompt' => /^OK\n/) @@ -53,10 +48,16 @@ puts 'No emulator is running.' end # FIXME(uwe): Change use of "killall" to use the Ruby Process API loop do + emulator_opts = '-partition-size 256' + emulator_opts << ' -no-snapshot-load' if no_snapshot + if !ON_MAC_OS_X && !ON_WINDOWS && ENV['DISPLAY'].nil? + emulator_opts << ' -no-window -no-audio' + end + `killall -0 #{emulator_cmd} 2> /dev/null` if $? == 0 `killall #{emulator_cmd}` 10.times do |i| `killall -0 #{emulator_cmd} 2> /dev/null` @@ -96,19 +97,30 @@ if ON_MAC_OS_X || ON_WINDOWS abis = target.slice(/(?<=ABIs : ).*/).split(', ') has_haxm = abis.find { |a| a =~ /x86/ } end - if has_haxm - abi_opt = '--abi x86' + # FIXME(uwe): The x86 emulator does not respect the heap setting and + # restricts to a 16MB heap on Android 2.3 which will crash any + # Ruboto app. Remove the first "if" below when heap setting works + # on x86 emulator. + # https://code.google.com/p/android/issues/detail?id=37597 + # https://code.google.com/p/android/issues/detail?id=61596 + if sdk_level == 10 + abi_opt = '--abi armeabi' else - if [17, 16, 15, 13, 11].include? sdk_level - abi_opt = '--abi armeabi-v7a' - elsif sdk_level == 10 - abi_opt = '--abi armeabi' + if has_haxm + abi_opt = '--abi x86' + else + if [17, 16, 15, 13, 11].include? sdk_level + abi_opt = '--abi armeabi-v7a' + elsif sdk_level == 10 + abi_opt = '--abi armeabi' + end end end + # EMXIF puts `echo n | android create avd -a -n #{avd_name} -t android-#{sdk_level} #{abi_opt} -c 64M -s HVGA` if $? != 0 puts 'Failed to create AVD.' @@ -126,11 +138,11 @@ File.write(avd_config_file_name, new_avd_config) if new_avd_config != old_avd_config new_snapshot = true end - puts 'Start emulator' + puts "Start emulator#{' without snapshot' if no_snapshot}" system "emulator -avd #{avd_name} #{emulator_opts} #{'&' unless ON_WINDOWS}" return if ON_WINDOWS 3.times do |i| sleep 1 @@ -172,11 +184,17 @@ print '.' sleep 1 end puts break if device_ready? + puts 'Device started, but failed to respond.' + unless no_snapshot + puts 'Retrying without loading snapshot.' + no_snapshot = true + end + else + puts 'Unable to start the emulator.' end - puts 'Unable to start the emulator.' end if new_snapshot puts 'Allow the emulator to calm down a bit.' sleep 15