From cf7a4f0fb6f4e17d7ce0f1c33118ed86c2134f2d Mon Sep 17 00:00:00 2001 From: Dave Johnson Date: Tue, 31 Aug 2010 13:21:23 -0700 Subject: [PATCH] Add more windows compatibility. run does not actually put the app on the simulator though --- lib/package.rb | 2 +- lib/run.rb | 16 ++++++++++++---- lib/update.rb | 2 +- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/package.rb b/lib/package.rb index 192964ba..6abe0be1 100644 --- a/lib/package.rb +++ b/lib/package.rb @@ -36,7 +36,7 @@ class Package @pkg = "com.phonegap.tmp#{ Time.now.usec }" # ensure a unique pkg # android sdk discovery ... could be better - @android_sdk_path = `which android`.gsub('/tools/android','') + @android_sdk_path = Dir.getwd[0,1] != "/" ? `android-sdk-path.bat android.bat`.gsub('\\tools','').gsub('\\', '\\\\\\\\') : `which android`.gsub('/tools/android','') @android_dir = File.expand_path(File.dirname(__FILE__).gsub('lib','')) @framework_dir = File.join(@android_dir, "framework") diff --git a/lib/run.rb b/lib/run.rb index 9b18961c..957774e9 100644 --- a/lib/run.rb +++ b/lib/run.rb @@ -15,7 +15,8 @@ class Run # if no path is supplied uses current directory for project def initialize(path) puts 'packaging www as phonegap/android project in ./tmp/android...' - @pkg = Package.new(path) + path = FileUtils.pwd if path.nil? || path == "" + @pkg = Package.new(path) @apk = File.join(@pkg.path, "bin", "#{ @pkg.name.gsub(' ','') }-debug.apk") build_apk first_device.nil? ? start_emulator : install_to_device @@ -23,18 +24,25 @@ class Run def build_apk puts 'building apk...' - `cd #{ @pkg.path }; ant debug;` + Dir.chdir(@pkg.path) + `ant debug;` end def install_to_device puts 'installing to device...' - `cd #{ @pkg.path }; ant install;` + Dir.chdir(@pkg.path) + `ant install;` end def start_emulator puts "No devices attached. Starting emulator w/ first avd...\n" $stdout.sync = true - IO.popen("emulator -avd #{ first_avd } -logcat all") do |f| + avd = first_avd + if (avd.nil? || avd == "") + puts "No Android Virtual Device (AVD) could be found. Please create one with the Android SDK." + return + end + IO.popen("emulator -avd #{ avd } -logcat all") do |f| until f.eof? puts f.gets if f.gets.include? 'Boot is finished' diff --git a/lib/update.rb b/lib/update.rb index 2a64c9a7..26814070 100644 --- a/lib/update.rb +++ b/lib/update.rb @@ -6,7 +6,7 @@ class Update def initialize @path = FileUtils.pwd - @android_sdk_path = `which android`.gsub('/tools/android','') + @android_sdk_path = Dir.getwd[0,1] != "/" ? `android-sdk-path.bat android.bat`.gsub('\\tools','').gsub('\\', '\\\\\\\\') : `which android`.gsub('/tools/android','') @android_dir = File.expand_path(File.dirname(__FILE__)) @framework_dir = File.join(@android_dir, "..", "framework") # puts "updating #{ @path } with phonegap from #{ @android_dir }"