Merging droidgap changes from LeRoux.

This commit is contained in:
filmaj 2010-02-24 15:36:07 -08:00
commit de8dc4af2a
2 changed files with 32 additions and 25 deletions

View File

@ -42,5 +42,5 @@ Importing a PhoneGap/Android app into Eclipse
For more info see For more info see
----------------- -----------------
http://docs.phonegap.com - [http://docs.phonegap.com](http://docs.phonegap.com)
http://wiki.phonegap.com - [http://wiki.phonegap.com](http://wiki.phonegap.com)

View File

@ -1,6 +1,7 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
require 'fileutils' require 'fileutils'
# ./droidgap /Users/brianleroux/Code/android-sdk-mac MyApp com.westcoastlogic example /Users/brianleroux/Desktop/MyApp
class Build class Build
attr_reader :android_sdk_path, :name, :pkg, :www, :path, :dir attr_reader :android_sdk_path, :name, :pkg, :www, :path, :dir
@ -14,6 +15,7 @@ class Build
def run def run
build_jar build_jar
create_android create_android
include_www
generate_manifest generate_manifest
copy_libs copy_libs
add_name_to_strings add_name_to_strings
@ -25,13 +27,13 @@ class Build
# then generates framework/phonegap.jar # then generates framework/phonegap.jar
def build_jar def build_jar
puts "Building the JAR..." puts "Building the JAR..."
FileUtils.rm "#{ @dir }framework#{@s}local.properties" if File.exists? "#{ @dir }framework#{@s}local.properties" %w(local.properties phonegap.js phonegap.jar).each do |f|
FileUtils.rm "#{ @dir }framework#{@s}phonegap.js" if File.exists? "#{ @dir }framework#{@s}phonegap.js" FileUtils.rm File.join(@framework_dir, f) if File.exists? File.join(@framework_dir, f)
FileUtils.rm "#{ @dir }framework#{@s}phonegap.jar" if File.exists? "#{ @dir }framework#{@s}phonegap.jar" end
open("#{ @dir }framework#{@s}local.properties", 'w') do |f| open(File.join(@framework_dir, "local.properties"), 'w') do |f|
f.puts "sdk.dir=#{ @android_sdk_path }" f.puts "sdk.dir=#{ @android_sdk_path }"
end end
Dir.chdir(@dir + "framework") Dir.chdir(@framework_dir)
`ant jar` `ant jar`
Dir.chdir(@dir) Dir.chdir(@dir)
end end
@ -40,10 +42,15 @@ class Build
# TODO need to allow more flexible SDK targetting # TODO need to allow more flexible SDK targetting
# TODO validate Android SDK # TODO validate Android SDK
def create_android def create_android
puts "Creating Android project..." target_id = 5 # `android list targets` =~ /id:\s*(\d+).*android-5/ ? $1 : 5
`android create project -t 5 -k #{ @pkg } -a #{ @name } -n #{ @name } -p #{ @path }` puts "Creating Android project... #{ target_id }"
FileUtils.mkdir_p "#{ @path }#{@s}assets#{@s}www" `android create project -t #{ target_id } -k #{ @pkg } -a #{ @name } -n #{ @name } -p #{ @path }`
FileUtils.cp_r "#{ @www }#{ @s }.", "#{ @path }#{ @s }assets#{ @s }www#{ @s }" end
def include_www
puts "Adding www folder to project..."
FileUtils.mkdir_p File.join(@path, "assets", "www")
FileUtils.cp_r File.join(@www, "."), File.join(@path, "assets", "www")
end end
# creates an AndroidManifest.xml for the project # creates an AndroidManifest.xml for the project
@ -72,17 +79,17 @@ class Build
FileUtils.cp "#{ @dir }framework#{@s}res#{@s}drawable#{@s}icon.png", "#{ @path }#{@s}res#{@s}#{ e }#{@s}icon.png" FileUtils.cp "#{ @dir }framework#{@s}res#{@s}drawable#{@s}icon.png", "#{ @path }#{@s}res#{@s}#{ e }#{@s}icon.png"
end end
# concat JS and put into www folder. # concat JS and put into www folder.
Dir.chdir("#{ @dir }framework#{ @s }assets#{ @s }js") js_dir = File.join(@framework_dir, "assets", "js")
basedir = "."
js = Dir.new(basedir).entries phonegapjs = IO.read(File.join(js_dir, 'phonegap.js.base'))
phonegapjs = IO.read('phonegap.js.base');
js.each do |script| Dir.new(js_dir).entries.each do |script|
next if script[0].chr == "." or script == "phonegap.js.base" next if script[0].chr == "." or script == "phonegap.js.base"
phonegapjs += IO.read(script) phonegapjs << IO.read(File.join(js_dir, script))
phonegapjs += "\n\n" phonegapjs << "\n\n"
end end
Dir.chdir("#{ @dir}")
File.open("#{ @path }#{ @s }assets#{ @s }www#{ @s }phonegap.js", 'w') {|f| f.write(phonegapjs) } File.open(File.join(@path, "assets", "www", "phonegap.js"), 'w') {|f| f.write(phonegapjs) }
end end
# puts app name in strings # puts app name in strings
@ -149,7 +156,7 @@ else
name ............... The name of your application. name ............... The name of your application.
package_name ....... The name of your package (For example: com.nitobi.demo) package_name ....... The name of your package (For example: com.nitobi.demo)
www ................ The path to your www folder. (Wherein your HTML, CSS and JS app is.) www ................ The path to your www folder. (Wherein your HTML, CSS and JS app is.)
path ............... The path to generate the application. path ............... The path to generate the Android application.
EOF EOF
end end