mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-22 00:32:55 +08:00
More weird merge bs.
This commit is contained in:
parent
de8dc4af2a
commit
fcce200701
71
droidgap
71
droidgap
@ -3,12 +3,12 @@ require 'fileutils'
|
|||||||
|
|
||||||
# ./droidgap /Users/brianleroux/Code/android-sdk-mac MyApp com.westcoastlogic example /Users/brianleroux/Desktop/MyApp
|
# ./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
|
||||||
|
|
||||||
def initialize(*a)
|
def initialize(*a)
|
||||||
@android_sdk_path, @name, @pkg, @www, @path = a
|
@android_sdk_path, @name, @pkg, @www, @path = a
|
||||||
@s = File::SEPARATOR
|
@android_dir = File.expand_path(File.dirname(__FILE__))
|
||||||
@dir = Dir.pwd + @s
|
@framework_dir = File.join(@android_dir, "framework")
|
||||||
end
|
end
|
||||||
|
|
||||||
# runs the build script
|
# runs the build script
|
||||||
@ -20,7 +20,7 @@ class Build
|
|||||||
copy_libs
|
copy_libs
|
||||||
add_name_to_strings
|
add_name_to_strings
|
||||||
write_java
|
write_java
|
||||||
puts "Complete!"
|
puts "Complete!"
|
||||||
end
|
end
|
||||||
|
|
||||||
# removes local.properties and recreates based on android_sdk_path
|
# removes local.properties and recreates based on android_sdk_path
|
||||||
@ -35,7 +35,7 @@ class Build
|
|||||||
end
|
end
|
||||||
Dir.chdir(@framework_dir)
|
Dir.chdir(@framework_dir)
|
||||||
`ant jar`
|
`ant jar`
|
||||||
Dir.chdir(@dir)
|
Dir.chdir(@android_dir)
|
||||||
end
|
end
|
||||||
|
|
||||||
# runs android create project
|
# runs android create project
|
||||||
@ -49,35 +49,49 @@ class Build
|
|||||||
|
|
||||||
def include_www
|
def include_www
|
||||||
puts "Adding www folder to project..."
|
puts "Adding www folder to project..."
|
||||||
|
|
||||||
FileUtils.mkdir_p File.join(@path, "assets", "www")
|
FileUtils.mkdir_p File.join(@path, "assets", "www")
|
||||||
FileUtils.cp_r File.join(@www, "."), 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
|
||||||
def generate_manifest
|
def generate_manifest
|
||||||
puts "Generating manifest..."
|
puts "Generating manifest..."
|
||||||
manifest = ""
|
manifest = ""
|
||||||
open(@dir + 'framework/AndroidManifest.xml', 'r') do |old|
|
open(File.join(@framework_dir, "AndroidManifest.xml"), 'r') do |old|
|
||||||
manifest = old.read
|
manifest = old.read
|
||||||
manifest.gsub! 'android:versionCode="5"', 'android:versionCode="1"'
|
manifest.gsub! 'android:versionCode="5"', 'android:versionCode="1"'
|
||||||
manifest.gsub! 'package="com.phonegap"', "package=\"#{ @pkg }\""
|
manifest.gsub! 'package="com.phonegap"', "package=\"#{ @pkg }\""
|
||||||
manifest.gsub! 'android:name=".StandAlone"', "android:name=\".#{ @name }\""
|
manifest.gsub! 'android:name=".StandAlone"', "android:name=\".#{ @name }\""
|
||||||
manifest.gsub! 'android:minSdkVersion="5"', 'android:minSdkVersion="3"'
|
manifest.gsub! 'android:minSdkVersion="5"', 'android:minSdkVersion="3"'
|
||||||
end
|
end
|
||||||
open("#{ @path }#{@s}AndroidManifest.xml", 'w') { |x| x.puts manifest }
|
open(File.join(@path, "AndroidManifest.xml"), 'w') { |x| x.puts manifest }
|
||||||
end
|
end
|
||||||
|
|
||||||
# copies stuff from framework into the project
|
# copies stuff from framework into the project
|
||||||
# TODO need to allow for www import inc icon
|
# TODO need to allow for www import inc icon
|
||||||
def copy_libs
|
def copy_libs
|
||||||
puts "Copying over libraries and assets and creating phonegap.js..."
|
puts "Copying over libraries and assets and creating phonegap.js..."
|
||||||
FileUtils.cp "#{ @dir }framework#{@s}phonegap.jar", "#{ @path }#{@s}libs"
|
|
||||||
FileUtils.cp "#{ @dir }framework#{@s}res#{@s}values#{@s}strings.xml", "#{ @path }#{@s}res#{@s}values#{@s}strings.xml"
|
framework_res_dir = File.join(@framework_dir, "res")
|
||||||
FileUtils.cp "#{ @dir }framework#{@s}res#{@s}layout#{@s}main.xml", "#{ @path }#{@s}res#{@s}layout#{@s}main.xml"
|
app_res_dir = File.join(@path, "res")
|
||||||
FileUtils.cp "#{ @dir }framework#{@s}res#{@s}layout#{@s}preview.xml", "#{ @path }#{@s}res#{@s}layout#{@s}preview.xml"
|
|
||||||
%w(drawable-hdpi drawable-ldpi drawable-mdpi).each do |e|
|
FileUtils.mkdir_p File.join(@path, "libs")
|
||||||
FileUtils.cp "#{ @dir }framework#{@s}res#{@s}drawable#{@s}icon.png", "#{ @path }#{@s}res#{@s}#{ e }#{@s}icon.png"
|
FileUtils.cp File.join(@framework_dir, "phonegap.jar"), File.join(@path, "libs")
|
||||||
|
|
||||||
|
FileUtils.mkdir_p File.join(app_res_dir, "values")
|
||||||
|
FileUtils.cp File.join(framework_res_dir, "values","strings.xml"), File.join(app_res_dir, "values", "strings.xml")
|
||||||
|
|
||||||
|
FileUtils.mkdir_p File.join(app_res_dir, "layout")
|
||||||
|
%w(main.xml preview.xml).each do |f|
|
||||||
|
FileUtils.cp File.join(framework_res_dir, "layout", f), File.join(app_res_dir, "layout", f)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
%w(drawable-hdpi drawable-ldpi drawable-mdpi).each do |e|
|
||||||
|
FileUtils.mkdir_p File.join(app_res_dir, e)
|
||||||
|
FileUtils.cp File.join(framework_res_dir, "drawable", "icon.png"), File.join(app_res_dir, e, "icon.png")
|
||||||
|
end
|
||||||
|
|
||||||
# concat JS and put into www folder.
|
# concat JS and put into www folder.
|
||||||
js_dir = File.join(@framework_dir, "assets", "js")
|
js_dir = File.join(@framework_dir, "assets", "js")
|
||||||
|
|
||||||
@ -94,14 +108,14 @@ class Build
|
|||||||
|
|
||||||
# puts app name in strings
|
# puts app name in strings
|
||||||
def add_name_to_strings
|
def add_name_to_strings
|
||||||
puts "Adding some application name to strings.xml..."
|
puts "Adding some application name to strings.xml..."
|
||||||
x = "<?xml version=\"1.0\" encoding=\"utf-8\"?>
|
x = "<?xml version=\"1.0\" encoding=\"utf-8\"?>
|
||||||
<resources>
|
<resources>
|
||||||
<string name=\"app_name\">#{ @name }</string>
|
<string name=\"app_name\">#{ @name }</string>
|
||||||
<string name=\"go\">Snap</string>
|
<string name=\"go\">Snap</string>
|
||||||
</resources>
|
</resources>
|
||||||
"
|
"
|
||||||
open("#{ @path }#{@s}res#{@s}values#{@s}strings.xml", 'w') do |f|
|
open(File.join(@path, "res", "values", "strings.xml"), 'w') do |f|
|
||||||
f.puts x.gsub(' ','')
|
f.puts x.gsub(' ','')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -109,7 +123,7 @@ class Build
|
|||||||
# this is so fucking unholy yet oddly beautiful
|
# this is so fucking unholy yet oddly beautiful
|
||||||
# not sure if I should thank Ruby or apologize for this abusive use of string interpolation
|
# not sure if I should thank Ruby or apologize for this abusive use of string interpolation
|
||||||
def write_java
|
def write_java
|
||||||
puts "Writing application Java code..."
|
puts "Writing application Java code..."
|
||||||
j = "
|
j = "
|
||||||
package #{ @pkg };
|
package #{ @pkg };
|
||||||
|
|
||||||
@ -127,10 +141,11 @@ class Build
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
"
|
"
|
||||||
dir = "#{ @path }#{@s}src#{@s}#{ @pkg.gsub '.', '/' }";
|
|
||||||
cls = "#{ @name }.java"
|
code_dir = File.join(@path, "src", @pkg.gsub('.', File::SEPARATOR))
|
||||||
pth = File.join(dir,cls)
|
|
||||||
open(pth,'w') { |f| f.puts j.gsub(' ','') }
|
FileUtils.mkdir_p(code_dir)
|
||||||
|
open(File.join(code_dir, "#{@name}.java"),'w') { |f| f.puts j.gsub(' ','') }
|
||||||
end
|
end
|
||||||
#
|
#
|
||||||
end
|
end
|
||||||
@ -159,4 +174,4 @@ else
|
|||||||
path ............... The path to generate the Android application.
|
path ............... The path to generate the Android application.
|
||||||
|
|
||||||
EOF
|
EOF
|
||||||
end
|
end
|
Loading…
Reference in New Issue
Block a user