mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-01 02:12:58 +08:00
85 lines
2.5 KiB
Plaintext
85 lines
2.5 KiB
Plaintext
|
#!/usr/bin/env ruby
|
||
|
require 'fileutils'
|
||
|
|
||
|
# ./droidgap /Users/brianleroux/Code/android-sdk-mac MyApp com.westcoastlogic example /Users/brianleroux/Desktop/MyApp
|
||
|
class Build
|
||
|
attr_reader :android_sdk_path, :path
|
||
|
|
||
|
def initialize(*a)
|
||
|
@android_sdk_path, @path = a
|
||
|
@android_sdk_path = "/Users/davejohnson/Sdk/android-sdk-mac_86"
|
||
|
@android_dir = File.expand_path(File.dirname(__FILE__))
|
||
|
@framework_dir = File.join(@android_dir, "framework")
|
||
|
end
|
||
|
|
||
|
# runs the build script
|
||
|
def run
|
||
|
build_jar
|
||
|
copy_libs
|
||
|
puts "Complete!"
|
||
|
end
|
||
|
|
||
|
# removes local.properties and recreates based on android_sdk_path
|
||
|
# then generates framework/phonegap.jar
|
||
|
def build_jar
|
||
|
puts "Building the JAR..."
|
||
|
%w(local.properties phonegap.js phonegap.jar).each do |f|
|
||
|
FileUtils.rm File.join(@framework_dir, f) if File.exists? File.join(@framework_dir, f)
|
||
|
end
|
||
|
open(File.join(@framework_dir, "local.properties"), 'w') do |f|
|
||
|
f.puts "sdk.dir=#{ @android_sdk_path }"
|
||
|
end
|
||
|
Dir.chdir(@framework_dir)
|
||
|
`ant jar`
|
||
|
Dir.chdir(@android_dir)
|
||
|
end
|
||
|
|
||
|
# copies stuff from framework into the project
|
||
|
# TODO need to allow for www import inc icon
|
||
|
def copy_libs
|
||
|
puts "Copying over libraries and assets and creating phonegap.js..."
|
||
|
|
||
|
FileUtils.mkdir_p File.join(@path, "libs")
|
||
|
FileUtils.cp File.join(@framework_dir, "phonegap.jar"), File.join(@path, "libs")
|
||
|
|
||
|
# concat JS and put into www folder.
|
||
|
js_dir = File.join(@framework_dir, "assets", "js")
|
||
|
|
||
|
phonegapjs = IO.read(File.join(js_dir, 'phonegap.js.base'))
|
||
|
|
||
|
Dir.new(js_dir).entries.each do |script|
|
||
|
next if script[0].chr == "." or script == "phonegap.js.base"
|
||
|
phonegapjs << IO.read(File.join(js_dir, script))
|
||
|
phonegapjs << "\n\n"
|
||
|
end
|
||
|
|
||
|
File.open(File.join(@path, "assets", "www", "js", "phonegap.js"), 'w') {|f| f.write(phonegapjs) }
|
||
|
end
|
||
|
#
|
||
|
end
|
||
|
|
||
|
|
||
|
if ARGV.length == 2
|
||
|
Build.new(*ARGV).run
|
||
|
else
|
||
|
puts <<-EOF
|
||
|
|
||
|
TestGap: Builds the JS and PhoneGap Android jar file and copies them to your project.
|
||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||
|
|
||
|
Creates a fresh app for hybrid mobile web hacking. Delicious robot!
|
||
|
|
||
|
Usage:
|
||
|
|
||
|
./testgap <android_sdk_path> <path>
|
||
|
|
||
|
Params:
|
||
|
|
||
|
android_sdk_path ... The path to your Android SDK install.
|
||
|
name ............... The name of your application.
|
||
|
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.)
|
||
|
path ............... The path to generate the Android application.
|
||
|
|
||
|
EOF
|
||
|
end
|