Bart Friederichs
Bart Friederichs

Reputation: 33533

Can I create a build variant in my app-project to include a Wear app?

I have an app that runs fine on a phone, but I want to port it now to an Android Wear device. It will be a stand-alone app (no communication with a connected phone*). I was thinking to create a product flavor in my Gradle file to build the Wear application, as it will use a lot of the same code (communication with server, connection with devices, etc).

android {
    productFlavors {
       full {
           ... stuff for my phone app ...
       }
       wear {
           ... stuff for my wear app ...
       }
    }
}

I already run into problems with dependencies, but before I try to fix those issues, I want to know if this a viable scenario, or should I create a separate Wear-project?

*) It is a very specific use case, customer-specific. This will run on only one Wear device, and not be distributed through the Play Store.

Upvotes: 0

Views: 118

Answers (2)

Sterling
Sterling

Reputation: 6635

From https://developer.android.com/wear/preview/features/app-distribution.html:

Note that it currently is not possible to create a single APK that works on a phone and watch.

In other words, to "port" your app to Wear, you'll need to make changes such that it'll no longer run (satisfactorily) on a phone. You don't need a new project, but you do need a new module.

The advice that @apesoczi gave was correct for Wear 1.x, but not for Wear 2. It's perfectly legitimate (and, in fact, recommended) for a Wear 2 app to function completely standalone, without an associated handheld app. I'd advise that you read the first few sections at https://developer.android.com/wear/preview/features/standalone-apps.html; they'll give you a good overview of the issues involved in targeting both Wear 1 and 2 with your app.

Upvotes: 1

apelsoczi
apelsoczi

Reputation: 1123

Quoted from :https://developer.android.com/training/wearables/apps/packaging.html

When publishing to users, you must package a wearable app inside of a handheld app, because users cannot browse and install apps directly on the wearable. If packaged properly, when users download the handheld app, the system automatically pushes the wearable app to the paired wearable.

The answer to your question - No. Also, if your wearable is going to be pulling data from the server, your app should be doing this work and relaying the data to the wearable. I would strongly encourage you not to attempt to make a wearable app without a mobile app. Doing so is exactly against each and every development and design pattern, what I'm trying to say is, your signing up for your own worst nightmare.

Upvotes: 0

Related Questions