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!
To change the build variant Android Studio uses, select Build > Select Build Variant in the menu bar. For projects without native/C++ code, the Build Variants panel has two columns: Module and Active Build Variant.
To download it, go to Tools > Android > SDK Manager, then click on the "SDK Tools" tab at the top of the new window. Then select the "Show Package Details" checkbox in the lower right-hand corner.
1. What Are Build Variants? Build variants are specific builds that you can produce from Gradle, based around shared core source code. While a standard app may have a debug and release build type, you can expand on this by adding flavor dimensions.
Build variants are the result of Gradle using a specific set of rules to combine settings, code, and resources configured in your build types and product flavors. Although you do not configure build variants directly, you do configure the build types and product flavors that form them.
You can create and configure build types in the module-level build.gradle file inside the android block. When you create a new module, Android Studio automatically creates the debug and release build types for you. Although the debug build type doesn't appear in the build configuration file, Android Studio configures it with debuggable true.
The Android plugin for Gradle provides a useful Gradle task that shows you how to organize your files for each of your build types, product flavors, and build variants. For example, the following sample from the task output describes where Gradle expects to find certain files for the "debug" build type:
However, you can create new source sets to control exactly what files Gradle compiles and packages for specific build types, product flavors (and combinations of product flavors when using flavor dimensions ), and build variants.
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
}
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.
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.
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