A few weeks ago, our crew decided that the Mirror API, and standard Android SDK were just not cutting it – We wanted our native apps to actually look and feel like just like the glass apps Google created. Thus began an epic quest by our fearless leader – Guy Paddock – to hunt down possible ways to accomplish this.
After watching the progression of his hunt, and working with the libraries for a few weeks – I determined it was too cool not to share. This is the first post in a trilogy of awesome things we have discovered with glass.
To the depths of Mordor (AKA GlassHome)!
After analyzing the various APKs found on Glass (thanks to Xenologer's teardown repos) Guy found that all of the libraries we wanted were already contained in the GlassHome.apk! He began by gathering all of the tools he’d need to successfully complete his journey. His arsenal included apktool, dex2jar, JD Decompiler, and the standard ADT eclipse package. With some crafty reverse engineering, copious amounts of caffeinated beverages, and a fair amount of experience tearing down software in college, Guy was successfully able to convert the libraries contained in the APK into android library projects that can be referenced by custom Glass apps.
Now for the part you’ve all be waiting for – instructions on how to do this yourself!
Step 1 – Tearing apart the GlassHome.apk
In order to get all the resources you’ll need to build the libraries, you must first acquire a copy of the GlassHome.apk, and since there are many other blogs and tutorials on how to do this I’m not going to cover it here.
Once you have the apk, you’ll need to unpack it – twice.
To start off, you’ll use apktool to obtain all the layouts, styles, and other resources necessary to work with the library. The standard documentation should be enough to accomplish this. This will be your reference material for building apps in the future – and at some point, you’ll have to pull in some of these assets when working with the libraries in your own projects. Most of the items you’ll need are just resources that you’ll put in the standard “res” folder of each of the library projects we’ll setup in a bit.
Next, open up the apk file, as a zip file, and pull out the “dex” file contained within. You’ll need to run this through dex2jar, which as the name suggests, will convert it to a jar file that is easier to work with. Unpack the jar and put the class files somewhere safe – we’ll come back to them shortly.
At this point you can also use JD Decompiler on the jar to get a Java interpretation of the source for reference.
Now you’ll want to open up ADT so we can setup the projects we’ll be using to build and package everything. Unpack the projects we’ve provided which have all the necessary build configurations already setup, and an Ant build script that will build it all into a usable jar. Once you unpack them, import them into ADT as is. You should now see the following 3 projects in your workspace.
Some of you might already be thinking this, and yes – the availability of the VoiceClient library DOES mean you can use custom voice commands, and yes, we do have it working. But to find out how we did it, you’ll have to wait until my next post (it is part two in the trilogy)!
Also, in case you are curious about how we determined what the 3 main libraries are, do a search through the class files you unpacked earlier for R.class. The packages they are contained in will tell you all you need to know about the library structure.
Now – back to the matter at hand.
Step 2: Building your libraries
Remember those class files you so lovingly set aside earlier? It’s time to put them to some good use. You’ll need to put the appropriate class files in the “classes” folder of each of the projects.
The classes in GoogleGlassLogging project will be:
The GoogleGlassVoiceClient project should include:
- speech (Yes, that’s the package name…)
The GoogleGlassUICommon project should include:
Once these are all setup, you’re ready to build them into a jar! Now with that Ant script that we included in the projects you can just build the project normally, and it will create the jar in the “libs” directory of the project.
Step 3: Profit!
Now that the projects contain a usable jar in the libs folder… you’re done! You can reference each of these projects in your own application as a standard library project!
For those of you that might be having trouble with any part of this, feel free to contact us and we’ll be more than happy to setup some time to work through it with you!