ruboto 1.0.3 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,11 +7,11 @@
7
7
  #######################################################
8
8
 
9
9
  Java::android.content.Context.class_eval do
10
- def toast(text, duration=5000)
10
+ def toast(text, duration=android.widget.Toast::LENGTH_SHORT)
11
11
  Java::android.widget.Toast.makeText(self, text, duration).show
12
12
  end
13
13
 
14
- def toast_result(result, success, failure, duration=5000)
14
+ def toast_result(result, success, failure, duration=android.widget.Toast::LENGTH_SHORT)
15
15
  toast(result ? success : failure, duration)
16
16
  end
17
17
  end
@@ -40,32 +40,37 @@ module Ruboto
40
40
  }
41
41
  option('activity') {
42
42
  argument :required
43
- description 'Name of your primary Activity. Defaults to the name of the application with Activity appended.'
43
+ description 'Name of your primary Activity. Defaults to the name of the application with "Activity" appended.'
44
44
  }
45
45
  option('path') {
46
46
  argument :required
47
47
  description 'Path to where you want your app. Defaults to the last part of the package name.'
48
48
  }
49
+ # FIXME(uwe): Change to cast to integer for better comparison
49
50
  option('target', 't') {
50
51
  argument :required
51
52
  defaults DEFAULT_TARGET_SDK
52
- description "Android version to target. Must begin with 'android-' (e.g., 'android-10' for gingerbread)"
53
- cast {|t| t =~ /^(\d+)$/ ? "android-#$1" : t}
54
- validate {|t| t =~ /^android-\d+$/}
53
+ description "Android version to target (e.g., 'android-19' or '19' for kitkat)"
54
+ cast { |t| t =~ /^(\d+)$/ ? "android-#$1" : t }
55
+ validate { |t| t =~ /^android-\d+$/ }
55
56
  }
56
57
  option('min-sdk') {
57
58
  argument :required
58
- description "Minimum android version supported. Must begin with 'android-'."
59
+ description "Minimum android version supported. (e.g., 'android-19' or '19' for kitkat)"
60
+ cast { |t| t =~ /^(\d+)$/ ? "android-#$1" : t }
61
+ validate { |t| t =~ /^android-\d+$/ }
59
62
  }
60
63
  option('with-jruby') {
61
- description 'Generate the JRuby jars jar'
62
- cast :boolean
64
+ description 'Install the JRuby jars in your libs directory. Optionally set the JRuby version to install. Otherwise the latest available version is installed.'
65
+ argument :optional
66
+ cast { |v| Gem::Version.new(v) }
67
+ validate { |v| Gem::Version.correct?(v) }
63
68
  }
64
69
  option('ruby-version') {
65
70
  description 'Using what version of Ruby? (e.g., 1.8, 1.9, 2.0)'
66
71
  argument :required
67
72
  cast :float
68
- validate {|rv| [1.8, 1.9, 2.0].include?(rv)}
73
+ validate { |rv| [1.8, 1.9, 2.0].include?(rv) }
69
74
  }
70
75
  option('force') {
71
76
  description 'Force creation of project even if the path exists'
@@ -108,7 +113,7 @@ module Ruboto
108
113
 
109
114
  Dir.chdir root do
110
115
  update_manifest min_sdk[/\d+/], target[/\d+/], true
111
- update_test true
116
+ update_test true, target[/\d+/].to_i
112
117
  update_assets
113
118
 
114
119
  if ruby_version
@@ -120,8 +125,10 @@ module Ruboto
120
125
  update_ruboto true
121
126
  update_icons true
122
127
  update_classes nil, 'exclude'
123
- update_jruby true if with_jruby
124
- update_dx_jar true if with_jruby
128
+ if with_jruby
129
+ update_jruby true, with_jruby
130
+ update_dx_jar true
131
+ end
125
132
  update_core_classes 'exclude'
126
133
 
127
134
  log_action('Generating the default Activity and script') do
@@ -138,8 +145,15 @@ module Ruboto
138
145
  include Ruboto::Util::Build
139
146
  include Ruboto::Util::Update
140
147
 
148
+ argument('version') {
149
+ required false
150
+ description 'The JRuby version to install.'
151
+ cast { |v| Gem::Version.new(v) }
152
+ validate { |v| Gem::Version.correct?(v) }
153
+ }
154
+
141
155
  def run
142
- update_jruby true
156
+ update_jruby true, params['version'].value
143
157
  end
144
158
  end
145
159
 
@@ -333,20 +347,25 @@ module Ruboto
333
347
  include Ruboto::Util::LogAction
334
348
  include Ruboto::Util::Update
335
349
 
336
- argument('what') {
337
- required
338
- # FIXME(uwe): Deprecated "ruboto update ruboto" in Ruboto 0.8.1. Remove september 2013.
339
- validate { |i| %w(jruby app ruboto).include?(i) }
340
- description "What do you want to update: 'app', 'jruby', or 'ruboto'"
341
- }
342
-
343
- option('force') {
344
- description "force an update even if the version hasn't changed"
345
- }
350
+ mode 'app' do
351
+ # FIXME(uwe): Change to cast to integer for better comparison
352
+ option('target', 't') {
353
+ argument :required
354
+ description "Android version to target (e.g., 'android-19' or '19' for kitkat)"
355
+ cast { |t| t =~ /^(\d+)$/ ? "android-#$1" : t }
356
+ validate { |t| t =~ /^android-\d+$/ }
357
+ }
358
+ option('with-jruby') {
359
+ description 'Install the JRuby jars in your libs directory. Optionally set the JRuby version to install. Otherwise the latest available version is installed. If the JRuby jars are already present in your project, this option is implied.'
360
+ argument :optional
361
+ cast { |v| Gem::Version.new(v) }
362
+ validate { |v| Gem::Version.correct?(v) }
363
+ }
364
+ option('force') {
365
+ description "force an update even if the version hasn't changed"
366
+ }
346
367
 
347
- def run
348
- case params['what'].value
349
- when 'app' then
368
+ def run
350
369
  force = params['force'].value
351
370
  old_version = read_ruboto_version
352
371
  if old_version && Gem::Version.new(old_version) < Gem::Version.new(Ruboto::UPDATE_VERSION_LIMIT)
@@ -358,21 +377,45 @@ module Ruboto
358
377
  system "ruboto _#{Ruboto::UPDATE_VERSION_LIMIT}_ update app"
359
378
  raise "Ruboto update app to #{Ruboto::UPDATE_VERSION_LIMIT} failed!" unless $? == 0
360
379
  end
361
- update_android
362
- update_test force
380
+
381
+ if (target = params['target'].value)
382
+ abort "Target must match android-<number>: got #{target}" unless target =~ /^android-(\d+)$/
383
+ abort "Minimum Android api level is #{MINIMUM_SUPPORTED_SDK}: got #{target}" unless $1.to_i >= MINIMUM_SUPPORTED_SDK_LEVEL
384
+ target_level = target[/\d+/].to_i
385
+ update_android(target_level)
386
+ update_test force, target_level
387
+ else
388
+ update_android
389
+ update_test force
390
+ end
391
+
363
392
  update_assets
364
393
  update_ruboto force
365
394
  update_classes old_version, force
366
395
  update_dx_jar force
367
- update_jruby force
396
+ update_jruby force, params['with-jruby'].value
368
397
  update_manifest nil, nil, force
369
398
  update_icons force
370
399
  update_core_classes 'exclude'
371
400
  update_bundle
372
- when 'jruby' then
373
- update_jruby(params['force'].value, true) || abort
374
- else
375
- raise "Unknown update target: #{params['what'].value.inspect}"
401
+ end
402
+ end
403
+
404
+ mode 'jruby' do
405
+
406
+ argument('version') {
407
+ required false
408
+ description 'The JRuby version to install. The jruby-jars gem of the same version should be installed on your system already.'
409
+ cast { |v| Gem::Version.new(v) }
410
+ validate { |v| Gem::Version.correct?(v) }
411
+ }
412
+
413
+ option('force') {
414
+ description "force an update even if the version hasn't changed"
415
+ }
416
+
417
+ def run
418
+ update_jruby(params['force'].value, params['version'].value, true) || abort
376
419
  end
377
420
  end
378
421
  end
@@ -386,8 +429,8 @@ module Ruboto
386
429
  argument :required
387
430
  default DEFAULT_TARGET_SDK
388
431
  arity -1
389
- cast {|t| t =~ /^(\d+)$/ ? "android-#$1" : t}
390
- validate {|t| t =~ /^android-\d+$/}
432
+ cast { |t| t =~ /^(\d+)$/ ? "android-#$1" : t }
433
+ validate { |t| t =~ /^android-\d+$/ }
391
434
  }
392
435
 
393
436
  option('yes', 'y') {
@@ -412,12 +455,17 @@ module Ruboto
412
455
  required unless api_level
413
456
  argument :required
414
457
  default(api_level) if api_level
415
- cast {|t| t =~ /^(\d+)$/ ? "android-#$1" : t}
416
- validate {|t| t =~ /^android-(\d+)$/ && sdk_level_name($1.to_i)}
458
+ cast { |t| t =~ /^(\d+)$/ ? "android-#$1" : t }
459
+ validate { |t| t =~ /^android-(\d+)$/ && sdk_level_name($1.to_i) }
460
+ }
461
+
462
+ option('no-snapshot', 's') {
463
+ extend Ruboto::Util::Emulator
464
+ description 'do not use a snapshot when starting the emulator'
417
465
  }
418
466
 
419
467
  def run
420
- start_emulator(params['target'].value)
468
+ start_emulator(params['target'].value, params['no-snapshot'].value)
421
469
  end
422
470
  end
423
471
 
@@ -11,7 +11,7 @@ module Ruboto
11
11
  Ruboto::SdkVersions::API_LEVEL_TO_VERSION[sdk_level] || "api_#{sdk_level}"
12
12
  end
13
13
 
14
- def start_emulator(sdk_level)
14
+ def start_emulator(sdk_level, no_snapshot)
15
15
  sdk_level = sdk_level.gsub(/^android-/, '').to_i
16
16
  STDOUT.sync = true
17
17
  if RbConfig::CONFIG['host_cpu'] == 'x86_64'
@@ -24,11 +24,6 @@ module Ruboto
24
24
  emulator_cmd = 'emulator-arm'
25
25
  end
26
26
 
27
- emulator_opts = '-partition-size 256'
28
- if !ON_MAC_OS_X && !ON_WINDOWS && ENV['DISPLAY'].nil?
29
- emulator_opts << ' -no-window -no-audio'
30
- end
31
-
32
27
  avd_name = "Android_#{sdk_level_name(sdk_level)}"
33
28
  new_snapshot = false
34
29
 
@@ -55,6 +50,12 @@ module Ruboto
55
50
 
56
51
  # FIXME(uwe): Change use of "killall" to use the Ruby Process API
57
52
  loop do
53
+ emulator_opts = '-partition-size 256'
54
+ emulator_opts << ' -no-snapshot-load' if no_snapshot
55
+ if !ON_MAC_OS_X && !ON_WINDOWS && ENV['DISPLAY'].nil?
56
+ emulator_opts << ' -no-window -no-audio'
57
+ end
58
+
58
59
  `killall -0 #{emulator_cmd} 2> /dev/null`
59
60
  if $? == 0
60
61
  `killall #{emulator_cmd}`
@@ -98,15 +99,26 @@ module Ruboto
98
99
  has_haxm = abis.find { |a| a =~ /x86/ }
99
100
  end
100
101
 
101
- if has_haxm
102
- abi_opt = '--abi x86'
102
+ # FIXME(uwe): The x86 emulator does not respect the heap setting and
103
+ # restricts to a 16MB heap on Android 2.3 which will crash any
104
+ # Ruboto app. Remove the first "if" below when heap setting works
105
+ # on x86 emulator.
106
+ # https://code.google.com/p/android/issues/detail?id=37597
107
+ # https://code.google.com/p/android/issues/detail?id=61596
108
+ if sdk_level == 10
109
+ abi_opt = '--abi armeabi'
103
110
  else
104
- if [17, 16, 15, 13, 11].include? sdk_level
105
- abi_opt = '--abi armeabi-v7a'
106
- elsif sdk_level == 10
107
- abi_opt = '--abi armeabi'
111
+ if has_haxm
112
+ abi_opt = '--abi x86'
113
+ else
114
+ if [17, 16, 15, 13, 11].include? sdk_level
115
+ abi_opt = '--abi armeabi-v7a'
116
+ elsif sdk_level == 10
117
+ abi_opt = '--abi armeabi'
118
+ end
108
119
  end
109
120
  end
121
+ # EMXIF
110
122
 
111
123
  puts `echo n | android create avd -a -n #{avd_name} -t android-#{sdk_level} #{abi_opt} -c 64M -s HVGA`
112
124
 
@@ -128,7 +140,7 @@ module Ruboto
128
140
  new_snapshot = true
129
141
  end
130
142
 
131
- puts 'Start emulator'
143
+ puts "Start emulator#{' without snapshot' if no_snapshot}"
132
144
  system "emulator -avd #{avd_name} #{emulator_opts} #{'&' unless ON_WINDOWS}"
133
145
  return if ON_WINDOWS
134
146
 
@@ -174,8 +186,14 @@ module Ruboto
174
186
  end
175
187
  puts
176
188
  break if device_ready?
189
+ puts 'Device started, but failed to respond.'
190
+ unless no_snapshot
191
+ puts 'Retrying without loading snapshot.'
192
+ no_snapshot = true
193
+ end
194
+ else
195
+ puts 'Unable to start the emulator.'
177
196
  end
178
- puts 'Unable to start the emulator.'
179
197
  end
180
198
 
181
199
  if new_snapshot
@@ -7,6 +7,7 @@ module Ruboto
7
7
  include Ruboto::Util::Verify
8
8
  REPOSITORY_BASE = 'http://dl-ssl.google.com/android/repository'
9
9
  REPOSITORY_URL = "#{REPOSITORY_BASE}/repository-8.xml"
10
+ SDK_DOWNLOAD_PAGE = 'http://developer.android.com/sdk/index.html?hl=sk'
10
11
 
11
12
  RUBOTO_GEM_ROOT = File.expand_path '../../../..', __FILE__
12
13
  WINDOWS_ELEVATE_CMD = "#{RUBOTO_GEM_ROOT}/bin/elevate_32.exe -c -w"
@@ -124,6 +125,30 @@ module Ruboto
124
125
  version
125
126
  end
126
127
 
128
+ def get_android_sdk_version
129
+ require 'net/http'
130
+ require 'uri'
131
+
132
+ # Get's the Page to Scrape
133
+ page_content = Net::HTTP.get(URI.parse(SDK_DOWNLOAD_PAGE))
134
+
135
+ case android_package_os_id
136
+ when MAC_OS_X
137
+ regex = '(\>android-sdk.*macosx.zip)'
138
+ when LINUX
139
+ regex = '(\>android-sdk.*.tgz)'
140
+ when WINDOWS
141
+ regex = '(\>installer_.*.exe)'
142
+ else #Error
143
+ nil
144
+ end
145
+
146
+ link = page_content.scan(/#{regex}/).to_s
147
+ version = link.match( /(\d+).(\d+).(\d+)/ )[0]
148
+
149
+ version
150
+ end
151
+
127
152
  #########################################
128
153
  #
129
154
  # Check Methods
@@ -164,8 +189,7 @@ module Ruboto
164
189
  found = File.exists?(@haxm_kext_loc)
165
190
  @haxm_kext_loc = nil unless found
166
191
  puts "#{'%-25s' % 'Intel HAXM'}: #{(found ? 'Found' : 'Not found')}"
167
- @haxm_installer_loc = File.join(android_package_directory, 'extras', 'intel', 'Hardware_Accelerated_Execution_Manager', 'IntelHAXM.dmg')
168
- @haxm_installer_loc = nil unless File.exists?(@haxm_installer_loc)
192
+ @haxm_installer_loc = Dir[File.join(android_package_directory, 'extras', 'intel', 'Hardware_Accelerated_Execution_Manager', 'IntelHAXM*.dmg')].first
169
193
  when LINUX
170
194
  @haxm_installer_loc = 'Not supported, yet.'
171
195
  @haxm_kext_loc = 'Not supported, yet.'
@@ -175,8 +199,7 @@ module Ruboto
175
199
  found = ($? == 0)
176
200
  @haxm_kext_loc = nil unless found
177
201
  puts "#{'%-25s' % 'Intel HAXM'}: #{(found ? 'Found' : 'Not found')}"
178
- @haxm_installer_loc = File.join(android_package_directory, 'extras', 'intel', 'Hardware_Accelerated_Execution_Manager', 'IntelHaxm.exe')
179
- @haxm_installer_loc = nil unless File.exists?(@haxm_installer_loc)
202
+ @haxm_installer_loc = Dir[File.join(android_package_directory, 'extras', 'intel', 'Hardware_Accelerated_Execution_Manager', 'IntelHaxm*.exe')].first
180
203
  return
181
204
  end
182
205
  end
@@ -264,7 +287,7 @@ module Ruboto
264
287
  `sudo #{installer} install -y #{package_name}`
265
288
  else
266
289
  puts
267
- puts 'You can install #{pretty_name} manually by:'
290
+ puts "You can install #{pretty_name} manually by:"
268
291
  puts "sudo #{installer} install #{package_name}"
269
292
  puts
270
293
  end
@@ -451,12 +474,12 @@ module Ruboto
451
474
  Dir.chdir File.expand_path('~/') do
452
475
  case android_package_os_id
453
476
  when MAC_OS_X
454
- asdk_file_name = "android-sdk_r#{get_tools_version}-#{android_package_os_id}.zip"
477
+ asdk_file_name = "android-sdk_r#{get_android_sdk_version}-#{android_package_os_id}.zip"
455
478
  download(asdk_file_name)
456
479
  unzip(accept_all, asdk_file_name)
457
480
  FileUtils.rm_f asdk_file_name
458
481
  when LINUX
459
- asdk_file_name = "android-sdk_r#{get_tools_version}-#{android_package_os_id}.tgz"
482
+ asdk_file_name = "android-sdk_r#{get_android_sdk_version}-#{android_package_os_id}.tgz"
460
483
  download asdk_file_name
461
484
  system "tar -xzf #{asdk_file_name}"
462
485
  FileUtils.rm_f asdk_file_name
@@ -469,7 +492,7 @@ module Ruboto
469
492
  # exit /b 1
470
493
  #)
471
494
 
472
- asdk_file_name = "installer_r#{get_tools_version}-#{android_package_os_id}.exe"
495
+ asdk_file_name = "installer_r#{get_android_sdk_version}-#{android_package_os_id}.exe"
473
496
  download(asdk_file_name)
474
497
  puts "Installing #{asdk_file_name}..."
475
498
  system "#{WINDOWS_ELEVATE_CMD} #{asdk_file_name}"
@@ -548,15 +571,14 @@ module Ruboto
548
571
  case android_package_os_id
549
572
  when MAC_OS_X
550
573
  system "hdiutil attach #{@haxm_installer_loc}"
551
- # FIXME(uwe): Detect volume
552
- # FIXME(uwe): Detect mpkg file with correct version.
553
- system 'sudo -S installer -pkg /Volumes/IntelHAXM_1.0.6/IntelHAXM_1.0.6.mpkg -target /'
574
+ fileName = Dir['/Volumes/IntelHAXM*/IntelHAXM*.mpkg'][0]
575
+ system "sudo -S installer -pkg #{fileName} -target /"
554
576
  when LINUX
555
577
  puts ' HAXM installation on Linux is not supported, yet.'
556
578
  return
557
579
  when WINDOWS
558
580
  cmd = @haxm_installer_loc.gsub('/', "\\")
559
- puts "Running the HAXM installer"
581
+ puts 'Running the HAXM installer'
560
582
  system %Q{#{WINDOWS_ELEVATE_CMD} "#{cmd}"}
561
583
  raise "Unexpected return code: #{$?.exitstatus}" unless $? == 0
562
584
  return