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'
}
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
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
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! :)
I'm making my first android wear app, but I can't get Android Studio working.
First I got the error
"Project with path ':wear' could not be found in project ':mobile'.
This was resolved by adding "include ':wear" in settings.gradle.
But then a new error occurs:
"Error:Module version Test2:mobile:unspecified, configuration 'wearApp' declares a dependency on configuration 'default' which is not declared in the module descriptor for Test2:wear:unspecified" .
What do I have to do to resolve that error?
Just in case it's needed: here's build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.verbraeken.joost.test2"
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
wearApp project(':wear')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.google.android.gms:play-services:8.3.0'
compile 'com.android.support:design:23.1.1'
}
settings.gradle:
include ':mobile'
include ':wear'
In Android Studio 3.0 the documentation for Migrate to the New Plugin says:
dependencies {
// This is the old method and no longer works for local
// library modules:
// debugCompile project(path: ':foo', configuration: 'debug')
// releaseCompile project(path: ':foo', configuration: 'release')
// Instead, simply use the following to take advantage of
// variant-aware dependency resolution. You can learn more about
// the 'implementation' configuration in the section about
// new dependency configurations.
implementation project(':foo')
// You can, however, keep using variant-specific configurations when
// targeting external dependencies. The following line adds 'app-magic'
// as a dependency to only the 'debug' version of your module.
debugImplementation 'com.example.android:app-magic:12.3'
}
So change this
debugCompile project(path: ':foo', configuration: 'debug')
releaseCompile project(path: ':foo', configuration: 'release')
to this
implementation project(':foo')
Error:Module version Test2:mobile:unspecified, configuration 'wearApp' declares a dependency on configuration 'default'
It means that a module (wearApp in your case) doesn't have a build.gradle file or a right configuration inside the build.gradle file.
Since you define a module in settings.gradle you have to provide a build.gradle for each module.
In your case:
root
|-- mobile
|----build.gradle
|-- wear
|----build.gradle
|--build.gradle
|--settings.gradle
If you're not using Android Studio 3.0, this worked for me, in your build.gradle lib:
publishNonDefault true
like this
android {
compileSdkVersion maxApiLevel.toInteger()
buildToolsVersion androidBuildToolsVersion
publishNonDefault true
[...]
}
And in your include build.gradle:
dependencies {
debugCompile project(path: ':foo', configuration: 'debug')
releaseCompile project(path: ':foo', configuration: 'release')
}
I am using ionic cordova for build my app, in my case the file build.grade was updated each time, I have to change the file "app_path>node_modules\cordova-android\bin\templates\cordova\lib\builders\GradleBuilder.js" from:
console.log('Subproject Path: ' + p);
var libName=p.replace(/[/\\]/g, ':').replace(name+'-','');
depsList += ' debugCompile(project(path: "' + libName + '", configuration: "debug"))';
insertExclude(p);
depsList += ' releaseCompile(project(path: "' + libName + '", configuration: "release"))';
insertExclude(p);
to:
console.log('Subproject Path: ' + p);
var libName=p.replace(/[/\\]/g, ':').replace(name+'-','');
depsList += ' compile project(\'' + libName + '\')';
insertExclude(p);
Works for me
The trick is:
dependencies {
// If the main app and wearable modules have the same flavors,
// the following configuration uses automatic dependency matching.
wearApp project(':wearable')
}
You don't have t set flavor or type build now, gradle 3.0 and above search for each flavor and buildType.
More info: https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration#variant_dependencies