Wear App and Custom Build Type with applicationIdSuffix

I have an app where I would like to add an app extension for Android Wear. The main application has three build types (debug, beta, and release). Beta builds have applicationIdSuffix , which allows me to install the play-store version and the current development version in parallel on one device. All this worked fine until I added a wearing app.

The main build.gradle application is as follows:

 apply plugin: 'com.android.application' android { ... defaultConfig { ... applicationId "com.example.mainApp" ... } buildTypes { debug { applicationIdSuffix '.debug' } beta { applicationIdSuffix '.beta' } release { } } } dependencies { ... wearApp project(':wear') } 

Wear-App has the same build types as the same applicationIdSuffix values. However, when I create a beta application (by calling gradle assembleBeta ), the build process builds :wear:assembleRelease instead of :wear:assembleBeta , so I get the following error message during assembly:

 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 say that the build process creates the correct build type when packaging the main application with the build type beta ?

+22
android android-wear android-gradle gradle
Aug 05 '14 at 14:16
source share
4 answers

Following the link posted by Scott Bartha ( http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Library-Publication ), I came up with the following:

In build.gradle wear app add publishNonDefault true (to publish all options):

 android { publishNonDefault true } 

In the build.gradle of the main application,
Replace

 wearApp project(':wear') 

By

 debugWearApp project(path:':wear', configuration: 'debug') releaseWearApp project(path:':wear', configuration: 'release') 
+17
Mar 19 '15 at 10:42
source share

You cannot do what you want; the module assembly option does not apply to the assembly of dependent modules during assembly. This is tracked at https://code.google.com/p/android/issues/detail?id=52962

Here it is possible to make one module dependent on a specific variant of another, as described in http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Library-Publication , but I don’t think that this mechanism can be expanded to make differential packaging for Wear applications.

+2
Aug 05 '14 at 16:11
source share

UPDATE Now there is official support for build options (see Kirill Leroux's answer). Therefore, this answer is outdated.




I found a very (very) ugly solution that has some drawbacks, but still works until there is support for build options for wearing applications.

I set a global variable in the rootProject file that contains the applicationIdSuffix current embedded main application.

In the build.gradle the main application, I added the following:

 // Set a global variable, depending on the currently built build-type. // This allows us to set the applicationIdSuffix of the wear app depending on // the build-type of the main app. android.applicationVariants.all { variant -> def task = variant.checkManifest def suffix = variant.buildType.applicationIdSuffix task.doLast { rootProject.ext.currentApplicationIdSuffix = suffix } } 

In the build.gradle application to wear out I added the following snapshots:

 android.applicationVariants.all { variant -> def task = variant.generateBuildConfig task.dependsOn(propagateApplicationIdSuffix) } task propagateApplicationIdSuffix << { project.android.buildTypes.all { type -> if (rootProject.hasProperty('currentApplicationIdSuffix')) { type.applicationIdSuffix = rootProject.ext.currentApplicationIdSuffix } } } 

This has several disadvantages:

  • You cannot create multiple variants (i.e. gradle assembleBeta assembleRelease ), because the wear application is only created once and therefore the second type of assembly fails.
  • gradle check fails due to reason 1
  • The wearing application is still built with the release assembly type, but the package name is simply changed according to the application identifier suffix of the main application.
+1
Aug 6 '14 at 10:55
source share

Do not worry, you CAN do what you want. I just did it for the enterprise application I'm working on.

The key is NOT to use the wearApp project (': wear'), as this only works when you use one app in your app to wear as the main app. And let them face it, how often does this situation happen in real life? If this happens, you are probably not using Gradle as much as possible.

You want to follow the instructions for the package manually in google google docs https://developer.android.com/training/wearables/apps/packaging.html#PackageManually

Unfortunately, this will require you to create your wearing app with the same app as the specific build option you are doing at the time, but this allows you to successfully pack the app to be worn in an app with multiple apps.

Also, the one trick I am doing is helping not to put the sock apk inside / res / raw, but in / assets, so you don't have to deal with Andriod Studio compressing apk.

Hope this helps! Within a couple of days I was crazy, found a solution. And the only textbook in French, and I had to translate the site to read it! https://translate.google.com/translate?hl=en&sl=auto&tl=en&u=http%3A%2F%2Fblog.octo.com%2Fpackager-une-application-android-wear-dans-la-vraie-vie% 2F

0
Nov 10 '14 at 16:57
source share



All Articles