I'm working on a multi-flavor app
. (gradle files below)
It uses a library called tracker
that follow the same flavors internal
and external
Now for the tricky part, come a new module called feature
, this one has no flavor but it needs the tracker
as dependency
app.gradle:
android {
buildTypes {
debug {
}
release {
}
}
flavorDimensions "target"
productFlavors {
internal {
dimension "target"
}
external {
dimension "target"
}
}
}
tracker.gradle:
android {
publishNonDefault true
buildTypes {
release {
}
debug {
}
}
flavorDimensions 'target'
productFlavors {
internal {
dimension "target"
}
external {
dimension "target"
}
}
}
feature.gradle:
android {
compileSdkVersion rootProject.ext.compileSdkVersion
defaultConfig {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
javaCompileOptions {
annotationProcessorOptions {
includeCompileClasspath false
}
}
}
}
}
dependencies {
implementation(
[...]
project(':tracker')
)
}
Here are the errors
when I try to gradle sync:
Unable to resolve dependency for ':feature@debug/compileClasspath': Could not resolve project :tracker.
Could not resolve project :tracker.
Required by:
project :feature
> Project :feature declares a dependency from configuration 'implementation' to configuration 'externalRelease' which is not declared in the descriptor for project :tracker.
Unable to resolve dependency for ':feature@debugAndroidTest/compileClasspath': Could not resolve project :tracker.
Could not resolve project :tracker.
[...]
My gradle version is 4.4.
In doc, Android developer and Android Plugin DSL Reference show that, should add follow code.
Android developer link image
Android Plugin DSL Reference image
but it not work for me. Finally I add follow code in feature.gradle.
Ok thanks to @ramin-eftekhari I managed to make it work
https://github.com/luxsypher/gradle-flavor-dependency
Try to add this in app
build.gradle
defaultConfig
block:From your question, what I get is that you trying to add the library
tracker
to yourfeature
module as dependency. In yourfeature.gradle
try the following:With Gradle 3.0, there are two new keywords
implementation
andapi
.compile
keyword is deprecated. You can useimplementation
as default. Useapi
especially when you have a transitive dependencies in your project (Module -> Lib1 -> Lib2), and you need to tell Gradle that the module wants to transitively export that dependency to other modules, so that it's available to them at both runtime and compile time.Good pictorial explanation:
Here is a good article telling difference between the
implementation
andapi
keyword: Implementation Vs Api in Android Gradle plugin 3.0Official doc explanation:
Here is a brief explanation from the official documentation Use the new dependency configurations:
Implementation:
api:
Hope this helps.
Update
For completeness sake, it seems there is a known issue with with gradle 4.1. Using version 4.3 helps. Thanks to Damien.