Corona note: Google Glass is not yet officially supported by Corona SDK, so any builds you do for it are at your own risk and we will be unable to help out with possible bugs/issues :). Good luck!
Let’s start with an overview and then go to a step-by-step tutorial.
What are barriers today that can make my current Corona Android build not work with Google Glass?
There are mainly two:
1) Code difference (User input, …)
2) How your app/game is initialized by the system
How do we solve that?
The 1st problem we solve via code, the same way that you maybe already doing today to differentiate between iOS and Android.
The 2nd problem we solve by editing your AndroidManifest.xml and add/edit some extra files. We show how to do this later on this post.
SOLVING PROBLEM #1 (Code difference)
What are the major adjustments to make on the code?
The main user input on Google Glass is the Voice. Unfortunately we don’t have support to capture that on Corona. So, let’s work on identifying the other two main user inputs that are performed by hand of the side of the Glass: tap and swipes
These inputs are captured as key events (like the back hardware key). So, if we run a simple app that has this code:
local function onKeyEvent( event )
print( "Key '", event.keyName, "' was pressed ", event.phase, " - code: ",
Runtime:addEventListener( "key", onKeyEvent )
We would get the following outputs.
03-18 14:44:54.194: I/Corona(11839): Key ' center ' was pressed down - code: 23
03-18 14:44:54.194: I/Corona(11839): Key ' center ' was pressed up - code: 23
03-18 14:45:00.062: I/Corona(11839): Key ' tab ' was pressed down - code: 61
03-18 14:45:00.062: I/Corona(11839): Key ' tab ' was pressed up - code: 61
03-18 14:45:00.101: I/Corona(11839): Key ' tab ' was pressed down - code: 61
03-18 14:45:00.101: I/Corona(11839): Key ' tab ' was pressed up - code: 61
03-18 14:45:00.163: I/Corona(11839): Key ' tab ' was pressed down - code: 61
03-18 14:45:00.163: I/Corona(11839): Key ' tab ' was pressed up - code: 61
03-18 14:45:00.483: I/Corona(11839): Key ' tab ' was pressed down - code: 61
03-18 14:45:00.483: I/Corona(11839): Key ' tab ' was pressed up - code: 61
Same output as SWIPE Forward
So, based on these outputs, you see that you can easily identify Taps and Swipes, although you will not be able to differentiate if the person is Swiping Forward or Back.
Another user input for Glass is the head movement that you can easily capture using accelerometer, gyroscope and compass, all of them already supported by Corona.
For a list of Google Glass gestures, please check this link.
How do we identify when my code is running on Glass?
You can use the following condition:
If string.lower(string.sub(system.getInfo("model"),1,5)) == "glass" then
-- code inside this block will run only on glass
I added that condition to the great device lib made by Rob Miracle (available here), making it easier to differentiate the parts of my code that needs to run only on Glass.
SOLVING PROBLEM #2 (App initialization)
On Glass, every app has a Voice activation command, so we need to create one for our Corona game.
You do that by editing you AndroidManifest.xml and adding/editing two more files. If you have a Corona Enterprise edition, you should be able to do them easily. If you have a Pro subscription (like me), you will have to do some extra work, but it can also be done.
So, this step-by-step is considering if you have a Pro subscription (If you are an Enterprise user, just ignore the steps that doesn’t apply to you).
1) Build your Corona game. You can use “Google Play” as a target store or “None”
2) Let’s unpack your apk so you can edit its AndroidManifest.xml and add/edit the extra files
When we say unpack files, most people directly try to change the apk extension to zip and then unzip it. This approach will not work, since the AndroidManifest.xml will not be on an editable format.
So, to unpack the apk we will use the apktool, which is free and available here.
You need to download the apktool and the system correspondent dependency file. So, in my case that use a Mac, I downloaded two files (apktool1.5.2.tar.bz2 and apktool-install-macosx-r05-ibot.tar.bz2). Just unzip them to same directory and you should be ready to go.
To unpack your apk build, just use the command:
./apktool d [your apk file]
In my case, I used (I had moved my apk file to the apktool dir):
./apktool d birdhunter.apk
After running that command, you will see that apktool created a new directory with your apk name. Inside of it you will find the AndroidManifest.xml and the resources files.
3) Edit your AndroidManifest.xml
We have to make 2 modifications in this file.
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="com.google.android.glass.action.VOICE_TRIGGER" />
<meta-data android:name="com.google.android.glass.VoiceTrigger" android:resource="@xml/trigger_show_me_a_demo" />
Second, you need to replace the package name attribute (which is inside the manifest tag) to your correct package name (for some reason the apktool doesn’t recognize your package name and uses “com.ansca.corona” wrongly. Thanks to the Corona Engineering team for helping me figured out that). So just replace:
package = “your.package.name”
In my case, I have:
package = “com.redbeachgames.birdhunter”
4) Add an extra resource file
Inside your unpacked apk, go to the “res” directory. There create a new directory called “xml”. Inside this new directory, create a file called “trigger_show_me_a_demo.xml”.
So, you should have “res/xml/trigger_show_me_a_demo.xml“. Add the following content to that xml file:
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2013 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
<trigger keyword="@string/show_me_a_demo" />
5) Edit your string.xml file
Now, go the res/values path and edit the string,xml file. Just add the following line inside the resources section.
<string name="show_me_a_demo">show me a demo</string>
The phrase “show me a demo” is the voice command that Glass will use as the voice trigger to your app/game.
You can use any phrase as the voice trigger during development. But for future publishing, Google will restrict that phrase to be one inside this list.
6) Pack back your files to an apk file
We now finished doing the required modifications to make your app/game work on Glass. Let’s now pack back the files into an apk file. You do that using apktool again.
./apktool b [apk dir name] [apk file.apk]
7) Sign your apk
Before installing the apk on Glass you need to sign this apk using a Debug/Distribution key. To facilitate the process, I have copied my distribution key file (“rbg.keystore”) to the same dir as the apk. To sign your apk, just run the command
jarsigner -verbose -keystore [your keystore file] [your apk file.apk] [your keystore alias]
In my case, I used:
jarsigner -verbose -keystore rbg.keystore birdhunter.apk RedBeachGames
Using the Corona Debug keystore file, the command would be (considering that you copied the debug.keystore to the same directory of your apk):
jarsigner -verbose -keystore debug.keystore birdhunter.apk androiddebugkey
The password for the Corona debug keystore is “android”.
If you find any problem in the signing process, try reading this Corona guide.
8) Done, now just install the apk on Glass
To install the apk on Glass, just use adb install command. Don’t forget to enable the Development mode on your Glass, otherwise the adb will not recognize it.
So, in my case, I used:
adb install birdhunter.apk
That is it! Following the steps above you should be able to successfully install your Corona game on Google Glass.
You can see our game Bird Hunter running on Google Glass here: