Android Studio and the Wear APK Packaging Issue

DISCLAIMER: Dear reader, in this blog post we discuss an issue for which we can provide no concrete solution. Ask any developer and these issues come up from time to time but are rarely documented. If you’ve come to this post looking for an answer, you’re in the wrong place. We’re unable to reproduce the original issue anymore making any further investigation near impossible. With that being said, if you have more information let’s start a conversation. We’d love to hear in the comments if you too have experienced this.

We recently ran into a curious problem while developing an app for Android Wear. The application in question came with a companion app designed to run on the user’s smartphone and interact with the watch. For those unfamiliar with how an Android Wear app gets to your watch, the Wear app gets bundled into a mobile app. When you install the mobile app on your phone, the Android OS will push the bundled Wear app to your paired smartwatch.

As a developer, you are building two apps and then bundling one inside the other. This is all handled quite nicely by Android Studio and you don’t really have to think much about it. That is, until something goes wrong. Just days before we were ready to submit, we put the finishing touches on the app, everything was working. Life was good. So we made our release candidate build and installed it. It didn’t work. The communication between the phone and watch wasn’t working, despite having just worked fine in a dev build. We checked again, the dev build works fine.

One big difference in the distribution of the wearable app between development and release is that during development, you push the latest build to the wearable device yourself, rather than bundling it into the mobile app. It avoids unnecessary steps and makes development faster. One of the last changes we had made was a minor tweak to the communication protocol between the two apps. So Android Studio, it seemed, was caching and bundling an old version of the Wear APK which didn’t have the updated path and therefore was not getting updates from the companion.

Our trust in the dev tools were a little shaken at this point. Knowing that things worked when we built and pushed the APK ourselves, we read up on other ways to package our wearable app. Google provides a couple different methods in their docs for bundling the APKs, but they all produced the same result. Ultimately, they all still rely on Android Studio to do the packaging, they just tell it to do so in a different way. It was time to step back from the problem and just think about it for a little while.

The next morning came and we were primed to tackle this problem head-on. Sipping coffee as our machines boot up, we share the crazy theories we’ve developed over the last evening and during our commutes. Firing up Android Studio with our game face on, we trigger another build just for sanity’s sake and -- COMPILE ERROR. Darn. Okay we broke something before leaving last night. No worries, it’s an easy fix. Second attempt at compiling. Generate our signed APK, install and… It works? Everything is fine…?


So there you have it. We don’t know what started the problem, but we have a couple ideas about how it may have stopped being a problem. When we accidentally introduced errors into the code, we may have forced a refresh of the project. Android Studio’s Clean/Rebuild Project functionality should be doing this anyway, and boy did we try that. We also restarted Android Studio numerous times in our quest for a fix, but one thing we hadn’t tried was restarting the computer. Perhaps when we came in the next morning and booted everything up fresh, that cleared some temp files that the IDE had cached.

We haven’t been able to recreate the issue to test our theories on how to fix it, so it’s really anyone’s guess. If you found this article because you ran into the same problem, hopefully you can find some solace in knowing it probably won’t last forever. Good luck, and let us know if you figure out the root cause!