gradle configurations/artifacts only uses "default" configuration - android

submodule (locallibs) build.gradle looks like the following:
configurations.create("default")
artifacts.add("default", file('defaultdistro.aar'))
configurations.create("distro2")
artifacts.add("distro2", file('distro2.aar'))
configurations.create("distro3")
artifacts.add("distro3", file('distro3.aar'))
the build.gradle for the app has a dependencies{} section that looks like the following:
dependencies {
debugCompile project(':locallibs')
flavor1ReleaseCompile project(path: ':locallibs', configuration: 'distro2')
flavor2ReleaseCompile project(path: ':locallibs', configuration: 'distro3')
}
The issue I'm having is that regardless of the flavor/build type the "default" configuration is always compiled so all of my flavors are including the "defaultdistro.aar" instead of the correct .aar distro.
I am expecting for flavor1 release build type to compile the distro2.aar but all flavors are compiling the defaultdistro.aar
EDIT: fixed the locallibs build.gradle representation
EDIT #2: the .aar distros are mutually exclusive

Related

Android Gradle 3.0.0 - add library dependency for specific flavors

My app includes a library and a 3 flavor debug, release and custom.
I don't want my app to include the library in 'custom' flavor
Prior to gradle 3.0 I used :
releaseCompile project(path: ':myLib', configuration: "release")
debugCompile project(path: ':..:myLib', configuration: "debug")
// 'custom' ignored
according to google migrate to android plugin for 3.0 I need to use implementation keyword with matchingFallbacks for 'custom' flavor.
I don't want to use 'matchingFallbacks' because I don't want my app to include the lib in 'custom' flavor.
Any idea how can I compile the lib only in debug and release?
edit
maybe its possible to add 'if' statement i.e:
if(flavor != custom){
implementation project 'myLib'
}
I think you can achieve it by using something like this:
dependencies {
// use only mylib for debug and release
releaseImplementation project(path: ':mylib')
debugImplementation project(path: ':mylib')
// this will be used by all the flavor
implementation "com.android.support:appcompat-v7:27.0.2'
}

Android Studio 3.0 submodule compile failed

App level build gradle dependencies
devCompile project(path: ':mymodule', configuration: 'devRelease')
proCompile project(path: ':mymodule', configuration: 'proRelease')
qaCompile project(path: ':mymodule', configuration: 'qaRelease')
offlineCompile project(path: ':mymodule', configuration: 'offlineRelease')
mentioned
publishNonDefault true
flavorDimensions "default"
I have tried This accepted answer but didn't work.
Update:
Look at the library gradle flavor that I want to compile. I have the same flavor mentioned in my app's Module.
dev {
manifestPlaceholders = [facebookId: "SOME_FACEBOOK_ID_1"]
}
pro {
manifestPlaceholders = [facebookId: "SOME_FACEBOOK_ID_2"]
}
qa {
manifestPlaceholders = [facebookId: "SOME_FACEBOOK_ID_3"]
}
offline {
manifestPlaceholders = [facebookId: "SOME_FACEBOOK_ID_4"]
}
You just need to reduce the details you provide:
compile project(path: ':mymodule')
The details what in which configuration is decided by gradle now by themselves. So it became way easier. Instead of 4 lines you just need the above now.
Also remove the publishNonDefault true from your modules gradle. It is not needed anymore.
Dependency management between modules has changed since Android Gradle Plugin 3.0.0. It automatically tries to matches flavours between your app and the libraries/modules it depends on.
See the documentation for more explanation!

How to use publishNonDefault but deploy only one artifact to maven

I have a library that I am deploying to maven. The library is included in a bigger test project with multiple apps. If I set publishNonDefault to true, then in my tests apps I can use:
releaseCompile project(path: ':library', configuration: 'release')
debugCompile project(path: ':library', configuration: 'debug')
however, in this case mavenDeployer is automatically uploading both release and debug artifacts to maven. If I set publishNonDefault to false, then my gradle system fails, because debug flavors can not be found.
Is there any way I can use both? Use debug/release configurations locally and deploy only release as the main artifact to maven?
Thanks
Please try this, it should work:
http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Library-Publication

Gradle group module dependencies based on flavors

The problem that I have is that the regular
dependencies {
compile project(path: ':moduleOne', configuration: "typeRelease")
}
is not enough for my app's purposes. I have quite a list of dependencies with different configurations (and flavors + build types) involved, and what I want to do now is to add some kind of a method to leverage those dependencies.
For example,
dependencies {
flavorOneAnalyticsCompile project(path: ':moduleOne', configuration: "typeRelease")
flavorOneFlurryCompile project(path: ':moduleOne', configuration: "typeRelease")
flavorOneCrashlyticsCompile project(path: ':moduleOne', configuration: "typeRelease")
flavorTwoAnalyticsCompile project(path: ':moduleOne', configuration: "typeStaging")
flavorTwoLoggingCompile project(path: ':moduleOne', configuration: "typeStaging")
}
Is it possible to say "I want all my build variants with FlavorOne to compile moduleOne with typeRelease configuration, and all build varians with FlavorTwo to compile moduleOne with typeStaging configuration"?
Does anybody know how to do it? Is this even possible? I have found here how to use flavor + build type dependencies, but it's quite ugly to have this big fat list of similarly-looking dependencies.
Thanks! :)

Defining dependencies for multiple variants

Say we have four build types: debug, qa, beta, and release.
We can define dependencies for specific variants like so:
dependencies {
// These dependencies are only included for debug and qa builds
debugCompile 'com.example:lib:1.0.0'
qaCompile 'com.example:lib:1.0.0'
}
Is there a way to compile these dependencies for multiple variants without repeating the artifact descriptor?
For example, I would like to do something like this:
dependencies {
internalCompile 'com.example:lib:1.0.0'
}
Where internalCompile would specify that the library is included for both debug and qa builds.
I believe that the solution lies within defining a new Gradle configuration, but if I create an internalCompile configuration I am unsure how to ensure that those dependencies are only compiled for qa and debug builds.
extendsFrom
The names of the configurations which this configuration extends from. The artifacts of the super configurations are also available in this configuration.
configurations {
// debugCompile and qaCompile are already created by the Android Plugin
internalCompile
}
debugCompile.extendsFrom(internalCompile)
qaCompile.extendsFrom(internalCompile)
dependencies {
//this adds lib to both debugCompile and qaCompile
internalCompile 'com.example:lib:1.0.0'
}
Alternatively:
You can create a collection of artifact descriptors and use it with multiple configurations.
List internalCompile = ["com.example:lib:1.0.0",
"commons-cli:commons-cli:1.0#jar",
"org.apache.ant:ant:1.9.4#jar"]
List somethingElse = ['org.hibernate:hibernate:3.0.5#jar',
'somegroup:someorg:1.0#jar']
dependencies {
debugCompile internalCompile
qaCompile internalCompile, somethingElse
}

Categories

Resources