Force configuration in the dependency in gradle android application

1.4k views Asked by At

I need to force the configuration in the gradle in my android application and my gradle verision is 3.0.1. the below is the old way of doing it and i need the equivalent of Gradle 3.0.

releaseCompile project(path: ':androidLibrary', configuration: 'debug')

My error version :

releaseImplementation project(path: ':androidLibrary', configuration: 'debug')

the above gives me an error message as

Error:Unable to resolve dependency for ':main@release/compileClasspath': Could not resolve project :androidLibrary."

Error:Unable to resolve dependency for ':main@releaseUnitTest/compileClasspath': Could not resolve project :androidLibrary.

1

There are 1 answers

1
Michael Osofsky On

Have you tried the following instead?

implementation project(':androidLibrary')

According to Google's Migrate to Android Plugin for Gradle 3.0.0, "targeting a specific variant of a local module dependency (for example, using configuration: 'debug') causes the following build error:"

Error:Unable to resolve dependency for ':app@debug/compileClasspath':
  Could not resolve project :library.
Error:Unable to resolve dependency for ':app@release/compileClasspath':
  Could not resolve project :library.

I think you're targeting a specific variant of a local module dependency when you use the release prefix in releaseImplementation and when you include configuration: 'debug' in this statement:

releaseImplementation project(path: ':androidLibrary', configuration: 'debug')

It goes on to recommend the following solution:

"You should instead configure your dependencies as follows":

dependencies {
    // This is the old method and no longer works for local
    // library modules:
    // debugImplementation project(path: ':library', configuration: 'debug')
    // releaseImplementation project(path: ':library', 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(':library')

    // 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'
}

source: Migrate dependency configurations for local modules