I have an app where I'd like to add an Android Wear app extension. The main app has three build types (debug, beta and release). Beta builds have an applicationIdSuffix
which allows me to install the play-store version and the current development version in parallel on the same device. This all worked fine until I added the wear app.
The main app`s build.gradle
looks like this:
apply plugin: 'com.android.application' android { ... defaultConfig { ... applicationId "com.example.mainApp" ... } buildTypes { debug { applicationIdSuffix '.debug' } beta { applicationIdSuffix '.beta' } release { } } } dependencies { ... wearApp project(':wear') }
The Wear-App has the same build types with the same applicationIdSuffix values. However, when I build the beta app (by calling gradle assembleBeta
) the build process builds :wear:assembleRelease
instead of :wear:assembleBeta
which is why I get the following error message during build:
FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':app:handleBetaMicroApk'. > The main and the micro apps do not have the same package name.
How can I tell the build process to build the correct build type when packaging the main app with build type beta
?
Following the link posted by Scott Barta (http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Library-Publication) I came up with this :
In the build.gradle of the wear app, add publishNonDefault true
(to publish all variants):
android { publishNonDefault true }
In the build.gradle of the main app,
Replace
wearApp project(':wear')
By
debugWearApp project(path:':wear', configuration: 'debug') releaseWearApp project(path:':wear', configuration: 'release')
You can't do what you want; the build variant of a module isn't propagated to the builds of dependent modules on build. This is tracked in https://code.google.com/p/android/issues/detail?id=52962
There's a facility to make one module depend on a specific variant of another one, as documented in http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Library-Publication, but I don't think this mechanism can be extended to do differential packaging of Wear apps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With