ruboto 0.13.0.rc.0 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
data/RELEASE_DOC ADDED
@@ -0,0 +1,110 @@
1
+ Subject: [ANN] Ruboto 0.13.0 released!
2
+
3
+ The Ruboto team is pleased to announce the release of Ruboto 0.13.0.
4
+
5
+ Ruboto (JRuby on Android) is a platform for developing full stand-alone
6
+ apps for Android using the Ruby language and libraries. It includes
7
+ support libraries and generators for creating projects, classes, tests,
8
+ and more. The complete APIs of Android, Java, and Ruby are available to
9
+ you using the Ruby language.
10
+
11
+ New in version 0.13.0:
12
+
13
+ In this release we add support for Android API level 17 and the Android
14
+ SDK r22. There are improvements on the "ruboto setup" command, and
15
+ general preparations for the 1.0 release.
16
+
17
+ Features:
18
+
19
+ * Issue #176 Add option to allocate large heap at startup
20
+ * Issue #252 View constant conversion errors aren't very clear
21
+ * Issue #333 Prettier design for the Ruboto platform apk
22
+ * Issue #405 "ruboto setup" on Windows
23
+ * Issue #408 Setup: Need to look up the latest Android tool version
24
+ (instead of hard coding it) if we can
25
+ * Issue #409 Add support for Android SDK r22
26
+ * Issue #410 Add -y option to "ruboto setup" to automatically install
27
+ components, accept licenses, and add to configuration
28
+ * Issue #412 Enable starting the emulator without a project
29
+ * Issue #414 Add -t --target parameter to "ruboto setup" to set up for a
30
+ specific api level
31
+ * Issue #415 Update API xml file to cover android-17
32
+ * Issue #416 Add code for generating the API xml file
33
+ * Issue #422 Put RubotoActivity intent data directly in the Intent instead
34
+ of inside a Bundle
35
+ * Issue #423 Focus the "start_ruboto_activity" API
36
+
37
+ Bugfixes:
38
+
39
+ * Issue #264 Force rebuild of (release) apk when jar file is removed from
40
+ the libs directory
41
+ * Issue #268 Callback for Audio Focus
42
+ * Issue #285 Look into pause/restart issues for secondary Activities
43
+ * Issue #407 Process::Status#to_int not implemented (NotImplementedError)
44
+ with jruby 1.7.x and ruboto 0.11.0
45
+
46
+ Support:
47
+
48
+ * Issue #303 Ruboto should synchronise target in project.properties and
49
+ targetSdkVersion in AndroidManifest.xml
50
+ * Issue #314 Tool confusion: ruboto vs rake
51
+ * Issue #424 Initiliaze the new App
52
+
53
+ Documentation:
54
+
55
+ * Issue #258 Add welcome and information with links to RubotoCore
56
+ * Issue #427 Add sidebar to the WIKI
57
+
58
+ Internal:
59
+
60
+ * Issue #411 Use "ruboto setup -y" to install components in travis-ci
61
+ automated testing
62
+
63
+ Rejected:
64
+
65
+ * Issue #175 Rename "update_scripts" rake task to "update" for less typing
66
+ * Issue #259 Link RubotoCore platform apk version to JRuby version
67
+ * Issue #261 Rename RubotoCore platform apk display name to Ruboto
68
+ * Issue #337 Change default for "ruboto gen app" to include JRuby in the
69
+ app
70
+
71
+ You can find a complete list of issues here:
72
+
73
+ * https://github.com/ruboto/ruboto/issues?state=closed&milestone=25
74
+
75
+
76
+ Installation:
77
+
78
+ To use Ruboto, you need to install a Ruby implementation. Then do
79
+ (possibly as root/administrator)
80
+
81
+ gem install ruboto
82
+ ruboto setup
83
+
84
+ To create a project do
85
+
86
+ ruboto gen app --package <your.package.name>
87
+ cd <project directory>
88
+ ruboto setup
89
+
90
+ To run an emulator for your project
91
+
92
+ cd <project directory>
93
+ ruboto emulator
94
+
95
+ To run your project
96
+
97
+ cd <project directory>
98
+ rake install start
99
+
100
+ You can find an introductory tutorial at
101
+ https://github.com/ruboto/ruboto/wiki
102
+
103
+ If you have any problems or questions, come see us at http://ruboto.org/
104
+
105
+ Enjoy!
106
+
107
+
108
+ --
109
+ The Ruboto Team
110
+ http://ruboto.org/
data/Rakefile CHANGED
@@ -1,4 +1,5 @@
1
1
  $:.unshift('lib') unless $:.include?('lib')
2
+ require 'date'
2
3
  require 'rake/clean'
3
4
  require 'rexml/document'
4
5
  require 'ruboto/version'
@@ -7,6 +8,7 @@ require 'ruboto/sdk_versions'
7
8
  require 'uri'
8
9
  require 'net/https'
9
10
 
11
+ PROJECT_DIR = File.expand_path(File.dirname(__FILE__))
10
12
  PLATFORM_PROJECT = File.expand_path('tmp/RubotoCore', File.dirname(__FILE__))
11
13
  PLATFORM_DEBUG_APK = "#{PLATFORM_PROJECT}/bin/RubotoCore-debug.apk"
12
14
  PLATFORM_DEBUG_APK_BAK = "#{PLATFORM_PROJECT}/bin/RubotoCore-debug.apk.bak"
@@ -15,6 +17,10 @@ PLATFORM_CURRENT_RELEASE_APK = File.expand_path('tmp/RubotoCore-release.apk', Fi
15
17
  MANIFEST_FILE = 'AndroidManifest.xml'
16
18
  GEM_FILE = "ruboto-#{Ruboto::VERSION}.gem"
17
19
  GEM_SPEC_FILE = 'ruboto.gemspec'
20
+ README_FILE = 'README.md'
21
+ BLOG_DIR = "#{File.dirname PROJECT_DIR}/ruboto.github.com/_posts"
22
+ RELEASE_BLOG = "#{BLOG_DIR}/#{Date.today}-Ruboto-#{Ruboto::VERSION}-release-doc.md"
23
+ RELEASE_BLOG_GLOB = "#{BLOG_DIR}/*-Ruboto-#{Ruboto::VERSION}-release-doc.md"
18
24
 
19
25
  CLEAN.include('ruboto-*.gem', 'tmp')
20
26
 
@@ -66,8 +72,8 @@ desc 'Generate an example app'
66
72
  task :example => :install do
67
73
  require 'ruboto/sdk_locations'
68
74
  EXAMPLE_FILE = File.expand_path("examples/RubotoTestApp_#{Ruboto::VERSION}_tools_r#{Ruboto::SdkLocations::ANDROID_TOOLS_REVISION}.tgz", File.dirname(__FILE__))
69
- examples_glob = "#{EXAMPLE_FILE.slice(/^.*?_\d+\.\d+\.\d+/)}*"
70
- sh "git rm #{examples_glob}" unless Dir[examples_glob].empty?
75
+ EXAMPLES_GLOB = "#{EXAMPLE_FILE.slice(/^.*?_\d+\.\d+\.\d+/)}*"
76
+ sh "git rm #{EXAMPLES_GLOB}" unless Dir[EXAMPLES_GLOB].empty?
71
77
  puts "Creating example app #{EXAMPLE_FILE}"
72
78
  app_name = 'RubotoTestApp'
73
79
  Dir.chdir File.dirname(EXAMPLE_FILE) do
@@ -84,9 +90,14 @@ class String
84
90
  end
85
91
  end
86
92
 
93
+ desc 'Update the README with the Ruboto description.'
94
+ file README_FILE => 'lib/ruboto/description.rb' do
95
+ File.write(README_FILE, File.read(README_FILE).sub(/(?<=\n\n).*(?=\nInstallation)/m, Ruboto::DESCRIPTION))
96
+ end
97
+
87
98
  desc 'Generate release docs for a given milestone'
88
- task :release_docs do
89
- raise "\n This task requires Ruby 1.9 or newer to parse JSON as YAML.\n\n" if RUBY_VERSION == '1.8.7'
99
+
100
+ def get_github_issues
90
101
  puts 'GitHub login:'
91
102
  begin
92
103
  require 'rubygems'
@@ -129,7 +140,11 @@ task :release_docs do
129
140
  milestone_name = issues[0] ? issues[0]['milestone']['title'] : "No issues for milestone #{milestone}"
130
141
  milestone_description = issues[0] ? issues[0]['milestone']['description'] : "No issues for milestone #{milestone}"
131
142
  milestone_description = milestone_description.split("\r\n").map(&:wrap).join("\r\n")
132
- categories = {'Features' => 'feature', 'Bugfixes' => 'bug', 'Internal' => 'internal', 'Support' => 'support', 'Documentation' => 'documentation', 'Pull requests' => nil, 'Other' => nil}
143
+ categories = {
144
+ 'Features' => 'feature', 'Bugfixes' => 'bug', 'Support' => 'support',
145
+ 'Documentation' => 'documentation', 'Pull requests' => nil,
146
+ 'Internal' => 'internal', 'Rejected' => 'rejected', 'Other' => nil
147
+ }
133
148
  grouped_issues = issues.group_by do |i|
134
149
  labels = i['labels'].map { |l| l['name'] }
135
150
  cat = nil
@@ -143,10 +158,16 @@ task :release_docs do
143
158
  cat ||= 'Other'
144
159
  cat
145
160
  end
161
+ return categories, grouped_issues, milestone, milestone_description, milestone_name
162
+ end
163
+
164
+ task :release_docs do
165
+ raise "\n This task requires Ruby 1.9 or newer to parse JSON as YAML.\n\n" if RUBY_VERSION == '1.8.7'
166
+ categories, grouped_issues, milestone, milestone_description, milestone_name = get_github_issues
146
167
 
147
168
  puts '=' * 80
148
169
  puts
149
- puts <<EOF
170
+ release_candidate_doc = <<EOF
150
171
  Subject: [ANN] Ruboto #{milestone_name} release candidate
151
172
 
152
173
  Hi all!
@@ -178,30 +199,35 @@ If you find a bug or have a suggestion, please file an issue in the issue tracke
178
199
  --
179
200
  The Ruboto Team
180
201
  http://ruboto.org/
181
-
182
202
  EOF
183
203
 
184
- puts '=' * 80
185
- puts
186
- puts "Subject: [ANN] Ruboto #{milestone_name} released!"
187
- puts
188
- puts "The Ruboto team is pleased to announce the release of Ruboto #{milestone_name}."
189
- puts
190
- puts Ruboto::DESCRIPTION.gsub("\n", ' ').wrap
191
- puts
192
- puts "New in version #{milestone_name}:\n"
193
- puts
194
- puts milestone_description
204
+ puts release_candidate_doc
205
+ File.write('RELEASE_CANDICATE_DOC', release_candidate_doc)
206
+
195
207
  puts
196
- (categories.keys & grouped_issues.keys).each do |cat|
197
- puts "#{cat}:\n\n"
198
- grouped_issues[cat].each { |i| puts %Q{* Issue ##{i['number']} #{i['title']}}.wrap(2) }
199
- puts
200
- end
201
- puts "You can find a complete list of issues here:\n\n"
202
- puts "* https://github.com/ruboto/ruboto/issues?state=closed&milestone=#{milestone}\n\n"
208
+ puts '=' * 80
203
209
  puts
204
- puts <<EOF
210
+ release_doc = <<EOF
211
+ Subject: [ANN] Ruboto #{milestone_name} released!
212
+
213
+ The Ruboto team is pleased to announce the release of Ruboto #{milestone_name}.
214
+
215
+ #{Ruboto::DESCRIPTION.gsub("\n", ' ').wrap}
216
+
217
+ New in version #{milestone_name}:
218
+
219
+ #{milestone_description}
220
+
221
+ #{(categories.keys & grouped_issues.keys).map do |cat|
222
+ "#{cat}:\n
223
+ #{grouped_issues[cat].map { |i| %Q{* Issue ##{i['number']} #{i['title']}}.wrap(2) }.join("\n")}
224
+ "
225
+ end.join("\n")}
226
+ You can find a complete list of issues here:
227
+
228
+ * https://github.com/ruboto/ruboto/issues?state=closed&milestone=#{milestone}
229
+
230
+
205
231
  Installation:
206
232
 
207
233
  To use Ruboto, you need to install a Ruby implementation. Then do
@@ -219,7 +245,7 @@ To create a project do
219
245
  To run an emulator for your project
220
246
 
221
247
  cd <project directory>
222
- rake emulator
248
+ ruboto emulator
223
249
 
224
250
  To run your project
225
251
 
@@ -237,9 +263,34 @@ Enjoy!
237
263
  --
238
264
  The Ruboto Team
239
265
  http://ruboto.org/
240
-
241
266
  EOF
267
+
268
+ puts release_doc
269
+ puts
242
270
  puts '=' * 80
271
+
272
+ unless Gem::Version.new(Ruboto::VERSION).prerelease?
273
+ header = <<EOF
274
+ ---
275
+ title : Ruboto #{Ruboto::VERSION}
276
+ layout: post
277
+ ---
278
+ EOF
279
+ File.write('RELEASE_DOC', release_doc)
280
+ Dir.chdir BLOG_DIR do
281
+ output = `git status --porcelain`
282
+ old_blog_posts = Dir[RELEASE_BLOG_GLOB] - [RELEASE_BLOG]
283
+ sh "git rm -f #{old_blog_posts.join(' ')}" unless old_blog_posts.empty?
284
+ File.write(RELEASE_BLOG, header + release_doc)
285
+ sh "git add -f #{RELEASE_BLOG}"
286
+ if output.empty?
287
+ `git commit -m "* Added release blog for Ruboto #{Ruboto::VERSION}"`
288
+ sh 'git push'
289
+ else
290
+ puts "Workspace not clean!\n#{output}"
291
+ end
292
+ end
293
+ end
243
294
  end
244
295
 
245
296
  desc 'Fetch download stats form rubygems.org'
@@ -320,7 +371,7 @@ task :stats do
320
371
  end
321
372
 
322
373
  desc 'Push the gem to RubyGems'
323
- task :release => [:clean, :gem] do
374
+ task :release => [:clean, README_FILE, :release_docs, :gem] do
324
375
  output = `git status --porcelain`
325
376
  raise "Workspace not clean!\n#{output}" unless output.empty?
326
377
  sh "git tag #{Ruboto::VERSION}"
@@ -328,7 +379,7 @@ task :release => [:clean, :gem] do
328
379
  sh "gem push #{GEM_FILE}"
329
380
  Rake::Task[:example].invoke
330
381
  sh "git add #{EXAMPLE_FILE}"
331
- sh "git commit -m '* Added example app for Ruboto #{Ruboto::VERSION} tools r#{Ruboto::SdkLocations::ANDROID_TOOLS_REVISION}' \"#{examples_glob}\""
382
+ sh "git commit -m '* Added example app for Ruboto #{Ruboto::VERSION} tools r#{Ruboto::SdkLocations::ANDROID_TOOLS_REVISION}' \"#{EXAMPLES_GLOB}\""
332
383
  sh 'git push'
333
384
  end
334
385
 
@@ -4,7 +4,6 @@ require 'time'
4
4
  require 'rake/clean'
5
5
  require 'rexml/document'
6
6
  require 'timeout'
7
- require 'net/telnet'
8
7
 
9
8
  ON_WINDOWS = (RbConfig::CONFIG['host_os'] =~ /mswin|mingw/i)
10
9
 
@@ -50,7 +49,7 @@ end
50
49
  new_dx_content = File.read(dx_filename).dup
51
50
 
52
51
  xmx_pattern = ON_WINDOWS ? /^set defaultXmx=-Xmx(\d+)(M|m|G|g|T|t)/ : /^defaultMx="-Xmx(\d+)(M|m|G|g|T|t)"/
53
- MINIMUM_DX_HEAP_SIZE = 1536
52
+ MINIMUM_DX_HEAP_SIZE = 1600
54
53
  if new_dx_content =~ xmx_pattern &&
55
54
  ($1.to_i * 1024 ** {'M' => 2, 'G' => 3, 'T' => 4}[$2.upcase]) < MINIMUM_DX_HEAP_SIZE*1024**2
56
55
  puts "Increasing max heap space from #$1#$2 to #{MINIMUM_DX_HEAP_SIZE}M in #{dx_filename}"
@@ -86,22 +85,34 @@ GEM_LOCK_FILE = "#{GEM_FILE}.lock"
86
85
  RELEASE_APK_FILE = File.expand_path "bin/#{build_project_name}-release.apk"
87
86
  APK_FILE = File.expand_path "bin/#{build_project_name}-debug.apk"
88
87
  TEST_APK_FILE = File.expand_path "test/bin/#{build_project_name}Test-debug.apk"
89
- JRUBY_JARS = Dir[File.expand_path 'libs/jruby-*.jar']
88
+ JRUBY_JARS = Dir[File.expand_path 'libs/{jruby-*,dx}.jar']
89
+ JARS = Dir[File.expand_path 'libs/*.jar'] - JRUBY_JARS
90
90
  RESOURCE_FILES = Dir[File.expand_path 'res/**/*']
91
91
  JAVA_SOURCE_FILES = Dir[File.expand_path 'src/**/*.java']
92
92
  RUBY_SOURCE_FILES = Dir[File.expand_path 'src/**/*.rb']
93
- APK_DEPENDENCIES = [MANIFEST_FILE, RUBOTO_CONFIG_FILE, BUNDLE_JAR] + JRUBY_JARS + JAVA_SOURCE_FILES + RESOURCE_FILES + RUBY_SOURCE_FILES
93
+ CLASSES_CACHE = "#{PROJECT_DIR}/bin/#{build_project_name}-debug-unaligned.apk.d"
94
+ APK_DEPENDENCIES = [MANIFEST_FILE, RUBOTO_CONFIG_FILE, BUNDLE_JAR, CLASSES_CACHE] + JRUBY_JARS + JARS + JAVA_SOURCE_FILES + RESOURCE_FILES + RUBY_SOURCE_FILES
94
95
  KEYSTORE_FILE = (key_store = File.readlines('ant.properties').grep(/^key.store=/).first) ? File.expand_path(key_store.chomp.sub(/^key.store=/, '').sub('${user.home}', '~')) : "#{build_project_name}.keystore"
95
96
  KEYSTORE_ALIAS = (key_alias = File.readlines('ant.properties').grep(/^key.alias=/).first) ? key_alias.chomp.sub(/^key.alias=/, '') : build_project_name
96
97
  APK_FILE_REGEXP = /^-rw-r--r--\s+(?:system|\d+\s+\d+)\s+(?:system|\d+)\s+(\d+)\s+(\d{4}-\d{2}-\d{2} \d{2}:\d{2}|\w{3} \d{2}\s+(?:\d{4}|\d{2}:\d{2}))\s+(.*)$/
97
- # -rw-r--r-- system system 7487556 2013-04-21 14:01 org.ruboto.example.gps-1.apk
98
- # -rw-r--r-- 1 1000 1000 59252 Aug 15 2010 /data/app/org.update_test-1.apk
99
- # -rw-r--r-- 1 1000 1000 59265 Aug 15 01:11 /data/app/org.update2_test-1.apk
98
+ JRUBY_ADAPTER_FILE = "#{PROJECT_DIR}/src/org/ruboto/JRubyAdapter.java"
100
99
 
101
100
  CLEAN.include('bin', 'gen', 'test/bin', 'test/gen')
102
101
 
103
102
  task :default => :debug
104
103
 
104
+ if File.exists?(CLASSES_CACHE)
105
+ expected_jars = File.readlines(CLASSES_CACHE).grep(%r{#{PROJECT_DIR}/libs/(.*\.jar) \\}).map { |l| l =~ %r{#{PROJECT_DIR}/libs/(.*\.jar) \\}; $1 }
106
+ actual_jars = Dir['libs/*.jar'].map { |f| f =~ /libs\/(.*\.jar)/; $1 }
107
+ changed_jars = ((expected_jars | actual_jars) - (expected_jars & actual_jars))
108
+ unless changed_jars.empty?
109
+ puts "Jars have changed: #{changed_jars.join(', ')}"
110
+ FileUtils.touch(CLASSES_CACHE)
111
+ end
112
+ end
113
+
114
+ file CLASSES_CACHE
115
+
105
116
  file JRUBY_JARS => RUBOTO_CONFIG_FILE do
106
117
  next unless File.exists? RUBOTO_CONFIG_FILE
107
118
  jruby_jars_mtime = JRUBY_JARS.map { |f| File.mtime(f) }.min
@@ -124,7 +135,7 @@ task :debug => APK_FILE
124
135
 
125
136
  namespace :debug do
126
137
  desc 'build debug package if compiled files have changed'
127
- task :quick => [MANIFEST_FILE, RUBOTO_CONFIG_FILE, BUNDLE_JAR] + JRUBY_JARS + JAVA_SOURCE_FILES + RESOURCE_FILES do |t|
138
+ task :quick => APK_DEPENDENCIES - RUBY_SOURCE_FILES do |t|
128
139
  build_apk(t, false)
129
140
  end
130
141
  end
@@ -184,10 +195,13 @@ task :tag do
184
195
  sh 'git push origin master --tags'
185
196
  end
186
197
 
187
- desc 'Start the emulator'
198
+ # FIXME(uwe): Remove December 2013
199
+ desc 'Deprecated: Use "ruboto emulator" instead.'
188
200
  task :emulator do
189
- start_emulator(sdk_level)
201
+ puts '"rake emulator" is deprecated. Use "ruboto emulator" instead.'
202
+ sh 'ruboto emulator'
190
203
  end
204
+ # EMXIF
191
205
 
192
206
  desc 'Start the application on the device/emulator.'
193
207
  task :start do
@@ -212,11 +226,38 @@ file MANIFEST_FILE => PROJECT_PROPS_FILE do
212
226
  manifest = old_manifest.dup
213
227
  manifest.sub!(/(android:minSdkVersion=').*?(')/) { "#$1#{sdk_level}#$2" }
214
228
  manifest.sub!(/(android:targetSdkVersion=').*?(')/) { "#$1#{sdk_level}#$2" }
215
- File.open(MANIFEST_FILE, 'w') { |f| f << manifest } if manifest != old_manifest
229
+ if manifest != old_manifest
230
+ puts "\nUpdating #{File.basename MANIFEST_FILE} with target from #{File.basename PROJECT_PROPS_FILE}\n\n"
231
+ File.open(MANIFEST_FILE, 'w') { |f| f << manifest }
232
+ end
216
233
  end
217
234
 
218
235
  file RUBOTO_CONFIG_FILE
219
236
 
237
+ file JRUBY_ADAPTER_FILE => RUBOTO_CONFIG_FILE do
238
+ require 'yaml'
239
+ if (heap_alloc = YAML.load(File.read(RUBOTO_CONFIG_FILE))['heap_alloc'])
240
+ config = <<EOF
241
+ // BEGIN Ruboto HeapAlloc
242
+ @SuppressWarnings("unused")
243
+ byte[] arrayForHeapAllocation = new byte[#{heap_alloc} * 1024 * 1024];
244
+ arrayForHeapAllocation = null;
245
+ // END Ruboto HeapAlloc
246
+ EOF
247
+ else
248
+ config = <<EOF
249
+ // BEGIN Ruboto HeapAlloc
250
+ // @SuppressWarnings("unused")
251
+ // byte[] arrayForHeapAllocation = new byte[13 * 1024 * 1024];
252
+ // arrayForHeapAllocation = null;
253
+ // END Ruboto HeapAlloc
254
+ EOF
255
+ end
256
+ source = File.read(JRUBY_ADAPTER_FILE)
257
+ heap_alloc_pattern = %r{^\s*// BEGIN Ruboto HeapAlloc\n.*^\s*// END Ruboto HeapAlloc\n}m
258
+ File.open(JRUBY_ADAPTER_FILE, 'w'){|f| f << source.sub(heap_alloc_pattern, config)}
259
+ end
260
+
220
261
  file APK_FILE => APK_DEPENDENCIES do |t|
221
262
  build_apk(t, false)
222
263
  end
@@ -455,15 +496,6 @@ end
455
496
 
456
497
  # Methods
457
498
 
458
- API_LEVEL_TO_VERSION = {
459
- 7 => '2.1', 8 => '2.2', 10 => '2.3.3', 11 => '3.0', 12 => '3.1',
460
- 13 => '3.2', 14 => '4.0', 15 => '4.0.3', 16 => '4.1.2', 17 => '4.2.2',
461
- }
462
-
463
- def sdk_level_name
464
- API_LEVEL_TO_VERSION[sdk_level]
465
- end
466
-
467
499
  def sdk_level
468
500
  File.read(PROJECT_PROPS_FILE).scan(/(?:target=android-)(\d+)/)[0][0].to_i
469
501
  end
@@ -545,7 +577,7 @@ def build_apk(t, release)
545
577
  apk_file = release ? RELEASE_APK_FILE : APK_FILE
546
578
  if File.exist?(apk_file)
547
579
  changed_prereqs = t.prerequisites.select do |p|
548
- File.file?(p) && !Dir[p].empty? && Dir[p].map { |f| File.mtime(f) }.max > File.mtime(APK_FILE)
580
+ File.file?(p) && !Dir[p].empty? && Dir[p].map { |f| File.mtime(f) }.max > File.mtime(apk_file)
549
581
  end
550
582
  return false if changed_prereqs.empty?
551
583
  changed_prereqs.each { |f| puts "#{f} changed." }
@@ -662,167 +694,3 @@ def stop_app
662
694
  output = `adb shell ps | grep #{package} | awk '{print $2}' | xargs adb shell kill`
663
695
  output !~ /Operation not permitted/
664
696
  end
665
-
666
- def start_emulator(sdk_level)
667
- STDOUT.sync = true
668
- if RbConfig::CONFIG['host_cpu'] == 'x86_64'
669
- emulator_cmd = 'emulator64-arm'
670
- else
671
- emulator_cmd = 'emulator-arm'
672
- end
673
-
674
- emulator_opts = '-partition-size 256'
675
- if !ON_WINDOWS && ENV['DISPLAY'].nil?
676
- emulator_opts << ' -no-window -no-audio'
677
- end
678
-
679
- avd_name = "Android_#{sdk_level_name}"
680
- new_snapshot = false
681
-
682
- if `adb devices` =~ /emulator-5554/
683
- t = Net::Telnet.new('Host' => 'localhost', 'Port' => 5554, 'Prompt' => /^OK\n/)
684
- t.waitfor(/^OK\n/)
685
- output = ''
686
- t.cmd('avd name') { |c| output << c }
687
- t.close
688
- if output =~ /(.*)\nOK\n/
689
- running_avd_name = $1
690
- if running_avd_name == avd_name
691
- puts "Emulator #{avd_name} is already running."
692
- return
693
- else
694
- puts "Emulator #{running_avd_name} is running."
695
- end
696
- else
697
- raise "Unexpected response from emulator: #{output.inspect}"
698
- end
699
- else
700
- puts 'No emulator is running.'
701
- end
702
-
703
- loop do
704
- `killall -0 #{emulator_cmd} 2> /dev/null`
705
- if $? == 0
706
- `killall #{emulator_cmd}`
707
- 10.times do |i|
708
- `killall -0 #{emulator_cmd} 2> /dev/null`
709
- if $? != 0
710
- break
711
- end
712
- if i == 3
713
- print 'Waiting for emulator to die: ...'
714
- elsif i > 3
715
- print '.'
716
- end
717
- sleep 1
718
- end
719
- puts
720
- `killall -0 #{emulator_cmd} 2> /dev/null`
721
- if $? == 0
722
- puts 'Emulator still running.'
723
- `killall -9 #{emulator_cmd}`
724
- sleep 1
725
- end
726
- end
727
-
728
- if [17, 16, 15, 13, 11].include? sdk_level
729
- abi_opt = '--abi armeabi-v7a'
730
- elsif sdk_level == 10
731
- abi_opt = '--abi armeabi'
732
- end
733
-
734
- unless File.exists? "#{ENV['HOME']}/.android/avd/#{avd_name}.avd"
735
- puts "Creating AVD #{avd_name}"
736
- puts `echo n | android create avd -a -n #{avd_name} -t android-#{sdk_level} #{abi_opt} -c 64M -s HVGA`
737
- if $? != 0
738
- puts 'Failed to create AVD.'
739
- exit 3
740
- end
741
- avd_config_file_name = "#{ENV['HOME']}/.android/avd/#{avd_name}.avd/config.ini"
742
- old_avd_config = File.read(avd_config_file_name)
743
- heap_size = (File.read('AndroidManifest.xml') =~ /largeHeap/) ? 256 : 48
744
- new_avd_config = old_avd_config.gsub(/vm.heapSize=([0-9]*)/){|m| p m ; m.to_i < heap_size ? "vm.heapSize=#{heap_size}" : m}
745
- File.write(avd_config_file_name, new_avd_config) if new_avd_config != old_avd_config
746
- new_snapshot = true
747
- end
748
-
749
- puts 'Start emulator'
750
- system "emulator -avd #{avd_name} #{emulator_opts} #{'&' unless ON_WINDOWS}"
751
- return if ON_WINDOWS
752
-
753
- 3.times do |i|
754
- sleep 1
755
- `killall -0 #{emulator_cmd} 2> /dev/null`
756
- if $? == 0
757
- break
758
- end
759
- if i == 3
760
- print 'Waiting for emulator: ...'
761
- elsif i > 3
762
- print '.'
763
- end
764
- end
765
- puts
766
- `killall -0 #{emulator_cmd} 2> /dev/null`
767
- if $? != 0
768
- puts 'Unable to start the emulator. Retrying without loading snapshot.'
769
- system "emulator -no-snapshot-load -avd #{avd_name} #{emulator_opts} #{'&' unless ON_WINDOWS}"
770
- 10.times do |i|
771
- `killall -0 #{emulator_cmd} 2> /dev/null`
772
- if $? == 0
773
- new_snapshot = true
774
- break
775
- end
776
- if i == 3
777
- print 'Waiting for emulator: ...'
778
- elsif i > 3
779
- print '.'
780
- end
781
- sleep 1
782
- end
783
- end
784
-
785
- `killall -0 #{emulator_cmd} 2> /dev/null`
786
- if $? == 0
787
- print 'Emulator started: '
788
- 50.times do
789
- if `adb get-state`.chomp == 'device'
790
- break
791
- end
792
- print '.'
793
- sleep 1
794
- end
795
- puts
796
- if `adb get-state`.chomp == 'device'
797
- break
798
- end
799
- end
800
- puts 'Unable to start the emulator.'
801
- end
802
-
803
- if new_snapshot
804
- puts 'Allow the emulator to calm down a bit.'
805
- sleep 15
806
- end
807
-
808
- system '(
809
- set +e
810
- for i in 1 2 3 4 5 6 7 8 9 10 ; do
811
- sleep 6
812
- adb shell input keyevent 82 >/dev/null 2>&1
813
- if [ "$?" == "0" ] ; then
814
- set -e
815
- adb shell input keyevent 82 >/dev/null 2>&1
816
- adb shell input keyevent 4 >/dev/null 2>&1
817
- exit 0
818
- fi
819
- done
820
- echo "Failed to unlock screen"
821
- set -e
822
- exit 1
823
- ) &'
824
-
825
- system 'adb logcat > adb_logcat.log &'
826
-
827
- puts "Emulator #{avd_name} started OK."
828
- end