I know that if I make a library that uses product flavors, then when I use that library in an application, I can do this in a gradle:
dependencies {
flavor1Compile(path: '{path}', configuration: 'flavor1Config')
flavor2Compile(path: '{path}', configuration: 'flavor2Config')
}
I also know that I can do this:
dependencies {
debugCompile(path: '{path}', configuration: 'debugConfig')
releaseCompile(path: '{path}', configuration: 'releaseConfig')
}
What I want to do is essentially this:
dependencies {
flavor1DebugCompile(path: '{path}', configuration: 'flavor1DebugConfig')
flavor1ReleaseCompile(path: '{path}', configuration: 'flavor1ReleaseConfig')
flavor2DebugCompile(path: '{path}', configuration: 'flavor2DebugConfig')
flavor2ReleaseCompile(path: '{path}', configuration: 'flavor2ReleaseConfig')
}
But that code produces this:
Error:(30, 0) Gradle DSL method not found: 'flavor1DebugCompile()'
Possible causes:The project 'android' may be using a version of Gradle that does not contain the method.
Open Gradle wrapper fileThe build file may be missing a Gradle plugin.
Apply Gradle plugin
Is there a way to do this?
There is an open bug on the Android issue tracker to support this.
As of right now, you can accomplish this by declaring a configuration like so for each combination you want to use:
configurations {
flavor1DebugCompile
}
dependencies {
flavor1DebugCompile(path: '{path}', configuration: 'flavor1DebugConfig')
}
Related
I've an Android app in Android Studio. I'm using Gradle Version = 4.6, Android Tools Plugin Version=3.2.1. It has a app module (main) and a library module. And I hope all buildTypes depend on the same configuration.
my build.gradle(app):
dependencies {
api project(path: ':lib', configuration: 'custom')
}
But it is ERROR:
Unable to resolve dependency for ':app#debug/compileClasspath': Could not resolve project :lib.
Try to replace your code like below
implementation project('path: ':lib', configuration: 'custom'')
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!
I got a problem in an Android project.
For example, there are four modules: App, Lib1, Lib2, Lib3.
App:
compile project(":Lib1")
Lib1:
compile project(":Lib2")
Lib2:
compile project(":Lib3")
Now, I configure product flavor for Both App and Lib3 like this:
productFlavors {
formal {}
dev {}
}
When I assemble a build variant for App like :App:assembleFormalRelease, I want Lib3's formalRelease variant to be built.
==============
I know I can achieve this by adding the same productFlavors and configuring like the following in all modules.
configurations {
devReleaseCompile {}
devDebugCompile {}
formalReleaseCompile {}
formalDebugCompile {}
}
dependencies {
devReleaseCompile project(path:"xxx", configuration: "devRelease")
devDebugCompile project(path:"xxx", configuration: "devDebug")
formalReleaseCompile project(path:"xxx", configuration: "formalRelease")
formalDebugCompile project(path:"xxx", configuration: "formalDebug")
}
but there are more than FIVE levels of nested dependencies in my working project, I want to know if there is a more simple solution.
Thank you!
I think tasks dependency is what you need.Since assemble tasks are lazy load
In the App module:
tasks.whenTaskAdded { task ->
if(task.name.equals('assembleFormalRelease')
{task.dependsOn ':lib3:assembleFormalRelease'}
}
Does it work?any conflicts in your scenario?
Getting the below error when trying to build flavour types of my lib modules.
Error:(210, 0) Gradle DSL method not found: 'flavourOneReleaseCompile()'
Possible causes:<ul><li>The project 'MyProject' may be using a version of the Android Gradle plug-in that does not contain the method (e.g. 'testCompile' was added in 1.1.0).
Fix plugin version and sync project</li><li>The project 'MyProject' may be using a version of Gradle that does not contain the method.
Gradle settings</li><li>The build file may be missing a Gradle plugin.
Apply Gradle plugin</li>
build file
android{......}
configurations{
flavorOneDebugCompile{}
flavorOneReleaseCompileCompile{}
flavorTwoDebugCompile{}
flavorTworeleaseCompile{}
}
dependencies {
flavorOneDebugCompile project(path: ':lib', configuration: 'flavorOneDebug')
flavorOneReleaseCompile project(path: ':lib', configuration: 'flavorOneRelease')
flavorTwoDebugCompile project(path: ':lib', configuration: 'flavorTwoDebug')
flavorTwoReleaseCompile project(path: ':lib', configuration: 'flavorTwoRelease')
}
Im using
classpath 'com.android.tools.build:gradle:1.3.1'
i was following this guide on how to target specific build flavours
https://developer.android.com/studio/build/gradle-tips.html#target-specific-builds-with-dependency-configurations
You are using spelling mistake flavorOneReleaseCompileCompile in
configurations{
flavorOneDebugCompile{}
flavorOneReleaseCompileCompile{}
flavorTwoDebugCompile{}
flavorTworeleaseCompile{}
}
Try replacing flavorOneReleaseCompileCompile with flavorOneReleaseCompile
I have a working app in Android Studio using classpath 'com.android.tools.build:gradle-experimental:0.4.0' and gradle 2.8.
As mentioned in google docs, to include your wearable app with your APK, you need to declare the wear app into the phone app gradle file as dependency something like this:
dependencies {
//other dependencies
//wearApp project(':Wear')
wearApp project(path: ':Wear', configuration: 'google')
}
But I get an error on the line where I include my wear app with the error message:
Gradle sync failed: Gradle DSL method not found: 'wearApp()'
This is because the experimental gradle plugin is not recognizing this command ( this is for standard gradle)...
The question is, What is the command for including Wear app with gradle-experimental:0.4.0 plugin ???
** update
Added this to gradle also:
android.buildTypes {
debug {
debuggable = true
embedMicroApp = true // this should enable the WEAR command, idk...
}
release {
minifyEnabled = false
proguardFiles.add(file('proguard-rules.txt'))
}
}
I believe that when you have productFlavors defined in your build.gradle, you need to reference them in your dependencies section, like such:
dependencies {
// other dependencies
googleWearApp project(path: ':wear', configuration: 'google')
}
At least, this is what I'm doing in a similar situation. Give it a try and see if it works!