SmartWatch2+3 in one apk

So, I got into this thing when I developed a watch face for the SmartWatch 2 and wanted to see if I could combine it in any way to work with a SmartWatch 3 as well.

My route was a bit more strangled than the one I am about to present, but if nothing else, now that I’ve done that, you don’t have to!

Primary setup

The ingredients list, as of this writing, is straight forward. This is what you need before moving on:

  • Android Studio 1.0.2
  • Android SDK Tools 23.0.5
  • Android SDK Platform-tools 21
  • Sony Add-on SDK 3.0
  • Android SDK 5.0 (API21)

Step 1: Create a Wear (API21: Android 5.0) project

This is for the SmartWatch 3 part of this SmartWatch 2 and 3 mashup.

It is actually as simple as that sounds. In Android Studio, choose the File-menu -> New Project and decide what you’d like to name it along with all the other settings you’d like to use for your SmartWatch 3 project. NOTE! The package name is going to be extra important, as you will have to use that later on in this guide.

When you have ran through the wizard and managed to find yourself with a Wear project that compiles, let’s import a SmartExtensions project.

Step 2: Import one of the SmartExtension samples as a module

Using a sample project is a quick and easy way of getting the right dependencies in place for the SmartWatch 2 part of this mashup.

Importing a sample project is done by clicking the File-menu -> Import-module, browsing to the SmartExtensions sample folder directory (usually located in ANDROID_SDK/add-ons/addon-sony_add-on_sdk_3_0-sony-19/samples/SmartExtensions) and selecting one of the samples. The import wizard will automatically present you with the option of also importing the “SmartExtensionUtils” and “SmartExtensionAPI” projects. Make sure that you include these, or you will run into build issues because of missing dependencies.

NOTE! I chose the “HelloLayouts” sample during my tests. Any other sample should work but avoid importing the “SmartExtensionAPI” and “SmartExtensionUtils” projects, unless you want to create a project from scratch without any boiler plate setup from the samples.

Step 3: Do a bit of modifications to project files

Here’s the tricky part. It’s not that tricky though. You will need to:

  • Modify the SmartExtension sample package name
  • Creating release build signing configs

and do some edits to the following files:

  • The SmartExtension sample gradle file
  • The SmartExtension sample AndroidManifest

Modifying the package name

This took a bit of trial and error but in the end, the recipe I would use:

  1. Create a new package in the SmartExtension sample module that has the same name as the Wear module package name
  2. Drag-and-drop all the classes from the old package “com.example….hellolayouts” to the new package
  3. Delete the old package
  4. Open the AndroidManifest file in the SmartExtension sample and replace the old package name “com.example….hellolayouts” the new name
  5. Open the SmartExtension gradle file and replace the package name here as well, referenced as applicationId

Try to build (a clean may also be required) your SmartExtension sample module to see whether everything seem to be in the right places and don’t contain errors. I got some minor issues with imports to “com.sample….R” that had not been cleaned out. Deleting those manually worked out perfectly fine for me.

Modifying the gradle files to update references and build configs

To lay the last stones in the process, you will need to do some additional updates to gradle files, both the SmartExtension sample and the Wear app.

NOTE! These steps require you to have an Android keystore and the secrets that go with them:

  1. Open the Wear app gradle build file
  2. Add the signingConfigs declaration and reference as shown below:
android {
  signingConfigs {
    release {
      keyAlias 'YOUR_KEY_ALIAS'
      keyPassword 'YOUR_KEY_PASSWORD'
      storeFile file('PATH_TO_YOUR_KEYSTORE_FILE')
      storePassword 'YOUR_KEYSTORE_PASSWORD'
    }
  }
  ...
  buildTypes {
    release {
      ...
      signingConfig signingConfigs.release
    }
  }
  ...
}
  1. Open the SmartExtension sample gradle build file
  2. Add the same declarations and references as in step 2 above, but also include the following (replace ‘:app’ with the module name of your Wear module):
dependencies {
  ...
  wearApp project(':app')
}

Step 4: Configure the Build Variants

This is the last step before making the final build. Find the “Build Variants” panel in Android Studio (it’s usually located at the bottom left of the UI) and select release for the Wear app and the SmartExtension sample. Leave “SmartExtensionUtils” and “SmartExtensionAPI” on debug.

Select the SmartExtension sample as your build configuration, compile, run and deploy! (If the “Edit configuration” dialogue shows up, choose to not launch an Activity, as the sample does not have a Default one declared)

Step 5. Done!

Congratulations! You should now, given nothing breaks down on you, have a SmartWatch 2 and 3 combined Android Studio project!

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.