Programming in Tizen for the Samsung Gears 2 Smartwatch
A month or so ago, I got a Samsung Gears 2 watch. I was very excited to start programming for it, but have been too busy to really explore it, so I’ve been doing a little bit, here and there and finally have time to write a little bit about.
Background
First, a little background. I was pretty excited to see a watch running Tizen. One of previous cellphones was the Nokia N900, which ran a version of Linux called Maemo. I liked programming for Maemo and the Nokia N900. But Maemo was merged into MeeGo and my old N900 started falling apart so my Linux on mobile devices programming subsided as I became more involved in my current job.
Part of the reason I like open source development for mobile devices is that, in theory, it should lower the bar to entry making such programming more accessible. I’m not sure how well this has really worked out in practice, however, the community of Maemo developers was pretty good at it.
Unfortunately, Tizen on the Samsung Gears 2 Smartwatch really hasn’t developed a good open source community yet, as far as I can tell, and the documentation seems to me to be a bit obtuse. So, with that, let me share some of my experiences getting going programming the Gears 2 Smartwatch.
Installing the SDK
The first big caveat, I’m running on a Windows 8 based laptop. This presents plenty of additional challenges, but if I can get it running on this box, it should be possible to get it running a lot of places.
First step was to install Java. In theory, this should be nice and easy. However, these days, there are more and more different choices for flavors of Java. I installed Java SE Development Kit 8u5 - Windows x64.
I also downloaded the Tizen SDK. I wasn’t sure if I needed the Tizen SDK, the Tizen SDK for Wearable 1.0.0b1, and/or other parts. It now looks like all I really needed was the SDK for Wearable, but it doesn’t hurt to have both.
The next issue I ran into was that the install failed. Apparently, this is not a unique problem. There is a blog post about Installing Tizen SDK 2.0 on Windows 8 64 bit. After the install fails, the install manager is left in the f AppData\Local\Temp\tizensdk directory. In that directory, run javaw -jar InstallManager.jar, and you should be good to go.
At least, that worked for the Tizen SDK. However, when trying to run the Tizen SDK for Wearable, even that presented problems. I kept getting the error, “Cannot find repository http://”
I read through the Tizen forum Can't install Tizen Sdk for Wearable because of "Cannot find repository." There was a lot of discussion about HAXM, which I’ll get to later.
The comment at the bottom gave the working answer. How to install Tizen SDK for Wearable (Samsung Gear). You need to download the SDK image from the same place you downloaded the install manager, and then enter the location of the SDK image in the advanced options of the SDK Install Manager.
Installing HAXM
The installation of the Intel Hardware Accelerated Execution Manager went amazingly simply, especially given the problems installing the SDK.
However, I ran into one problem. The virtualization technology needed to be turned on in BIOS. To make things more complicated, my hard disk is encrypted so I don’t have a standard bootup process. The bootup also was set to boot without waiting for people to change BIOS settings, so it was a challenge to get the BIOS changed. I’m running an HP ENVY 15, and activating vt-x from bios gave me the information I needed, when I managed to hit the F10 quickly enough on Startup.
Learning the architecture
Being the old command line Linux programmer, I figured I should be able to connect into the Linux box (in this case the watch), bring up a shell prompt, and start developing. I’m also used to working with Google Glass which connects to the Internet via Wifi or Bluetooth tethering. With my Nokia N900, it would connect to the Internet, and then I could connect to the phone over the internet using Secure Shell, or even set up a web server on my phone. I was hoping to do something similar with the Samsung Gears 2 watch.
However, it appears as if the Gears 2 Watch is set up a bit differently. It communications with a Samsung Smartphone over Bluetooth, but does not use TCP/IP. The advantage of this is that you don’t need a special plan from your cellphone provider that permits Bluetooth tethering. However, it does significantly limit what you can do. I suspect someone will find a work around for this soon enough.
To deal with this the Gears 2 architecture is set up to run in a bunch of different modes, with applications running standalone on the watch, or communicating with an app on the phone. I have not dug deep enough to find if there is a decent generic proxy app for Gears 2, but I’m dubious. You can read more about the architecture here.
Starting the Emulator
The development environment is Eclipse. I started Eclipse from the \tizen-wearable-sdk\ide directory and started poking around. However, I couldn’t get the Gears 2 to show up and I had problems with the emulator.
While it should seem obvious how to set up the emulator, I scratched my head about it for a bit. So, the quick cheat sheet. In Eclipse, in the connection explorer in the lower left, click on the first icon entitled Emulation Manager. When the manager starts, click on Add New to create a new emulator. In the details on the right, enter the name of the emulator. I’ve created Test1 and Test2 using the defaults for all the other values. Click on Confirm at the bottom of that box.
Also, be sure you are doing this from the wearable-sdk. Otherwise, you’ll be setting up emulators for Tizen based smartphones.
Once you have your emulator created, click on the play button at the bottom of the emulator. This gets to wear I’ve run into different issues. I’ve tried launching the emulator manager multiple times and Eclipse complains that it is already running. Yet nothing show up in the list of available connections.
When I’ve clicked on the play button, nothing seems to happen, so I go on and try other things, which usually screw up everything. Be patient. On my machine, it takes about thirty seconds for the emulator to show up, and another thirty seconds before Eclipse discovers the emulator is running.
Once the emulator is running, you are ready to start testing.
Connecting the Watch
Again, this seems nice and straight forward. Connect the USB cable from the PC to the connector that snaps on the back of the Gears 2 watch. However, when I did that, I got nothing. It turns out that Windows needs driver updates to be able to recognize the USB device.
GUIDE: First Time with your new Tizen SDP - Drivers and certificate talks a bit about this and provides a link to SAMSUNG_USB_Driver_for_Mobile_Phones.zip I downloaded the zip file, ran the executable in it and the next time I connected my watch to my laptop, it showed up in the connection explorer.
Shell Access At Last!
With the watch connected, I could browse the files on my watch using Eclipse. I could also go into shell mode, using the command ‘sdb shell’ in the \tizen-wearable-sdk\tools directory. Looking at other sdb commands, there is ‘sdb root’ command. However, trying to enable root gives a Permission denied.
There is an article, [Hack] The Tizen Samsung Gear 2 and Gear 2 Neo get Root access I haven’t tried that yet since I haven’t gotten a need for root access yet.
And the development
I’ve been having problems with my machine crashing a bit recently, since I’ve started trying to develop for Gears 2. I’m not sure if the problem is with the IDE, the emulator, or completely unrelated, but it has been slowing down my testing. I did manage to side load a package on my watch using the commands in How to Install (sideload) .wgt app files on the Samsung Gear 2 smartwatch using SDB. This is also useful in finding out about certificates, which is an area I haven’t mastered yet. Once an application is slide loaded, removing it can be a challenge. How to uninstall an app in Tizen emulator? gives a good idea how to do it, except that the package id is in the config.xml file.
I’ve also run applications from Eclipse, which I’ll talk about more later.
I apologize for such a long detailed post about getting started with development for Gears 2. Hopefully, this will provide a good starting for others wanting to get going.