Android Studio Gradle - set module build variant
Asked Answered
O

2

10

I am setting up project that has a dependancy to one module, and I could successfully make APK file. All I did was adding

compile project(':ModuleName')

However I am wondering if I can have module dependancy with build variance. So, [Project:debug] depends on [Module:debug], and [Project:release] depends on [Module:release]

Thanks!

Odel answered 25/11, 2014 at 18:35 Comment(0)
C
3

At the moment the Gradle toolchain only builds libraries in the release variant by default, regardless of what you choose as your application build type. There are some suggested work arounds to that problem but they are mostly involved in your build configuration rather than anything with the dependency include.

The closest example I can think that is to what you want is to do the following;

dependencies {
    flavor1Compile project(path: ':lib1', configuration: 'flavor1Release')
    flavor2Compile project(path: ':lib1', configuration: 'flavor2Release')
}

But this is achieved through build flavours rather than build variants.

Carabineer answered 25/11, 2014 at 22:41 Comment(1)
That's good enough for now. Hope we will get more control later. Thanks.Odel
S
8

An update over Marcus answer:

I don't know since what version of Gradle /Android Studio, but now it's possible to do:

Update: publishNonDefault is now deprecated and not needed anymore. Just use the config further below.

###Library's build.gradle:

android {
    ...
    publishNonDefault true
}

App's build.gradle:

dependencies {
    debugCompile project(path: ':baseApp', configuration: 'debug')
    releaseCompile project(path: ':baseApp', configuration: 'release')
}

Changing the build variant of one of them in the Android Studio will change the build variant of the other.

Solingen answered 14/6, 2015 at 15:1 Comment(2)
Hello Diolor, after decompiling a class "BaseExtension" found this: public void setPublishNonDefault(boolean publishNonDefault) { this.logger.warn("publishNonDefault is deprecated and has no effect anymore. All variants are now published."); }Perfectionism
HI @Sergio. Yes publishNonDefault has been deprecated few months ago. I updated the answer. Thanks!Solingen
C
3

At the moment the Gradle toolchain only builds libraries in the release variant by default, regardless of what you choose as your application build type. There are some suggested work arounds to that problem but they are mostly involved in your build configuration rather than anything with the dependency include.

The closest example I can think that is to what you want is to do the following;

dependencies {
    flavor1Compile project(path: ':lib1', configuration: 'flavor1Release')
    flavor2Compile project(path: ':lib1', configuration: 'flavor2Release')
}

But this is achieved through build flavours rather than build variants.

Carabineer answered 25/11, 2014 at 22:41 Comment(1)
That's good enough for now. Hope we will get more control later. Thanks.Odel

© 2022 - 2024 — McMap. All rights reserved.