Last active
August 29, 2015 13:59
-
-
Save timothyclemans/10547356 to your computer and use it in GitHub Desktop.
Wear Script APK creation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
package="com.weariverse.<%= $package %>" | |
android:versionCode="1" | |
android:versionName="1.0"> | |
<uses-permission android:name="android.permission.CAMERA" /> | |
<uses-feature | |
android:name="android.hardware.camera" | |
android:required="false" /> | |
<uses-feature | |
android:name="android.hardware.camera.autofocus" | |
android:required="false" /> | |
<uses-feature | |
android:name="android.hardware.camera.front" | |
android:required="false" /> | |
<uses-feature | |
android:name="android.hardware.camera.front.autofocus" | |
android:required="false" /> | |
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> | |
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> | |
<uses-permission android:name="android.permission.RECORD_AUDIO" /> | |
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> | |
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /> | |
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" /> | |
<uses-permission android:name="android.permission.INTERNET" /> | |
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | |
<uses-permission android:name="android.permission.WAKE_LOCK" /> | |
<uses-permission android:name="android.permission.BLUETOOTH" /> | |
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /> | |
<uses-feature | |
android:glEsVersion="0x00020000" | |
android:required="true" /> | |
<uses-sdk | |
android:minSdkVersion="15" | |
android:targetSdkVersion="19" /> | |
<supports-screens | |
android:anyDensity="true" | |
android:largeScreens="true" | |
android:normalScreens="true" | |
android:resizeable="true" | |
android:smallScreens="true" /> | |
<application | |
android:allowBackup="true" | |
android:icon="@drawable/launcher" | |
android:label="@string/app_name"> | |
<activity android:name=".ui.WSActivity" | |
></activity> | |
<activity | |
android:name=".ui.QRActivity" | |
android:configChanges="keyboardHidden" | |
android:label="WearScript QR"></activity> | |
<activity | |
android:name=".ui.SetupActivity" | |
android:clearTaskOnLaunch="true" | |
android:configChanges="keyboardHidden" | |
android:exported="true" | |
android:label="@string/setup"></activity> | |
<activity | |
android:name=".ui.StopActivity" | |
android:clearTaskOnLaunch="true" | |
android:configChanges="keyboardHidden" | |
android:icon="@drawable/ic_stop" | |
android:label="@string/stop" | |
android:launchMode="singleInstance"></activity> | |
<activity | |
android:name=".ui.ScriptActivity" | |
android:configChanges="keyboardHidden" | |
android:label="@string/app_name" | |
android:launchMode="singleInstance"> | |
<intent-filter> | |
<action android:name="android.intent.action.MAIN" /> | |
<category android:name="android.intent.category.LAUNCHER" /> | |
<action android:name="com.google.android.glass.action.VOICE_TRIGGER" /> | |
</intent-filter> | |
<meta-data | |
android:name="com.google.android.glass.VoiceTrigger" | |
android:resource="@xml/voice_trigger" /> | |
</activity> | |
<activity | |
android:name=".ui.MenuActivity" | |
android:enabled="true" | |
android:label="@string/app_name" | |
android:theme="@style/MenuTheme"></activity> | |
<service android:name="com.weariverse.<%= $package %>.BackgroundService" /> | |
</application> | |
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'fileutils' | |
require 'erb' | |
require 'open-uri' | |
class Compiler | |
DEFAULT_SCRIPT = "<body style='width:640px; height:480px; overflow:hidden; margin:0' bgcolor='black'><center><h1 style='font-size:70px;color:#FAFAFA;font-family:monospace'>WearScript</h1><h1 style='font-size:40px;color:#FAFAFA;font-family:monospace'>When connected use playground to control<br><br>Docs @ wearscript.com</h1></center><script>function s() {WSRAW.say('Connected')};window.onload=function () {WSRAW.serverConnect('{{WSUrl}}', 's')}</script></body>" | |
def self.do path, nice_name, trigger | |
if path.include? 'http' | |
new_script = open(path) {|f| f.read} | |
else | |
new_script = File.read(path) | |
end | |
new_script.gsub! "\n", "\\n" | |
new_script.gsub! "\"", "\\\"" | |
path_to_wear_script = '/home/[[ username ]]/wearscript-android' | |
$package = nice_name.gsub(/[-\s]/,"_").downcase | |
$name = nice_name | |
$trigger = trigger | |
manifest_template = File.read('AndroidManifest.xml.erb') | |
trigger_template = File.read('voice_trigger_start.xml.erb') | |
strings_template = File.read('strings.xml.erb') | |
build_id = Time.now.to_i.to_s | |
build_path = "compiler/" + $package | |
FileUtils.mkdir_p "compiler" | |
FileUtils.rm_rf(build_path) | |
FileUtils.cp_r(path_to_wear_script, build_path) | |
FileUtils.cd build_path do | |
FileUtils.cd("WearScript/src/main") do | |
manifest = ERB.new(manifest_template, 0, "%<>").result | |
File.write("AndroidManifest.xml", manifest) | |
FileUtils.cd("java") do | |
FileUtils.mkpath("com/weariverse") | |
system("mv com/dappervision/wearscript com/weariverse/#{$package}") | |
Dir.glob(File.join("**", "*.java")) do |name| | |
text = File.read(name) | |
text.gsub!("com.dappervision.wearscript", "com.weariverse.#{$package}") | |
File.write name, text | |
end | |
FileUtils.cd("com/weariverse/#{$package}") do | |
service = File.read('BackgroundService.java') | |
service.gsub! DEFAULT_SCRIPT, new_script | |
File.write("BackgroundService.java", service) | |
end | |
end | |
FileUtils.cd("res") do | |
strings = ERB.new(strings_template, 0, "%<>").result | |
File.write("values/strings.xml", strings) | |
end | |
end | |
raise "Build failed" unless system "./gradlew build --debug" | |
FileUtils.mv("WearScript/build/apk/WearScript-debug-unaligned.apk", "../#{$package}-#{build_id}.apk") | |
end | |
return "compiler/#{$package}-#{build_id}.apk" | |
end | |
Compiler.do("#{ARGV[0]}", "#{ARGV[1]}", "#{ARGV[2]}" ) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<resources> | |
<string name="app_name"><%= $name %></string> | |
<string name="open">Open</string> | |
<string name="stop">Stop</string> | |
<string name="setup">Setup</string> | |
<string name="glass_voice_trigger"><%= $trigger %></string> | |
</resources> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment