Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle 4.0 Unable to find a matching configuration

I am trying to open my existing project in new Android Studio 3.0 canary 2. I updated Gradle according to instructions, changed names for dependency configurations but I continue to get next error:

Unable to resolve dependency for ':app@productionRelease/compileClasspath': 
Could not resolve project : abChat.

And in another window:

Error:Could not resolve all dependencies for configuration ':bankOK:betaNewApiInnerTestRuntimeClasspath'.
> Unable to find a matching configuration in project :abChat:
    - Configuration 'debugApiElements':
        - Required apiLvl 'ProductFlavorAttr{name=newApi}' but no value provided.
        - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'AndroidTypeAttr{name=Aar}' and found compatible value 'AndroidTypeAttr{name=Aar}'.
        - Required com.android.build.gradle.internal.dependency.BuildTypeAttr 'BuildTypeAttr{name=innerTest}' and found incompatible value 'BuildTypeAttr{name=debug}'.
        - Found com.android.build.gradle.internal.dependency.VariantAttr 'VariantAttr{name=debug}' but wasn't required.
        - Required org.gradle.api.attributes.Usage 'for runtime' and found incompatible value 'for compile'.
        - Required releaseType 'ProductFlavorAttr{name=beta}' but no value provided.
    - Configuration 'debugRuntimeElements':
        - Required apiLvl 'ProductFlavorAttr{name=newApi}' but no value provided.
        - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'AndroidTypeAttr{name=Aar}' and found compatible value 'AndroidTypeAttr{name=Aar}'.
        - Required com.android.build.gradle.internal.dependency.BuildTypeAttr 'BuildTypeAttr{name=innerTest}' and found incompatible value 'BuildTypeAttr{name=debug}'.
        - Found com.android.build.gradle.internal.dependency.VariantAttr 'VariantAttr{name=debug}' but wasn't required.
        - Required org.gradle.api.attributes.Usage 'for runtime' and found compatible value 'for runtime'.
        - Required releaseType 'ProductFlavorAttr{name=beta}' but no value provided.
    - Configuration 'releaseApiElements':
        - Required apiLvl 'ProductFlavorAttr{name=newApi}' but no value provided.
        - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'AndroidTypeAttr{name=Aar}' and found compatible value 'AndroidTypeAttr{name=Aar}'.
        - Required com.android.build.gradle.internal.dependency.BuildTypeAttr 'BuildTypeAttr{name=innerTest}' and found incompatible value 'BuildTypeAttr{name=release}'.
        - Found com.android.build.gradle.internal.dependency.VariantAttr 'VariantAttr{name=release}' but wasn't required.
        - Required org.gradle.api.attributes.Usage 'for runtime' and found incompatible value 'for compile'.
        - Required releaseType 'ProductFlavorAttr{name=beta}' but no value provided.
    - Configuration 'releaseRuntimeElements':
        - Required apiLvl 'ProductFlavorAttr{name=newApi}' but no value provided.
        - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'AndroidTypeAttr{name=Aar}' and found compatible value 'AndroidTypeAttr{name=Aar}'.
        - Required com.android.build.gradle.internal.dependency.BuildTypeAttr 'BuildTypeAttr{name=innerTest}' and found incompatible value 'BuildTypeAttr{name=release}'.
        - Found com.android.build.gradle.internal.dependency.VariantAttr 'VariantAttr{name=release}' but wasn't required.
        - Required org.gradle.api.attributes.Usage 'for runtime' and found compatible value 'for runtime'.
        - Required releaseType 'ProductFlavorAttr{name=beta}' but no value provided.

Here are our build types and flavors:

buildTypes {

        release {
           //...
        }

        debug {
           //...
        }

        innerTest {
            //...
        }
    }



flavorDimensions "releaseType", "apiLvl"
    productFlavors {
        prod {
            dimension "releaseType"
            //...
        }
        beta {
            dimension "releaseType"
            //...
        }
        oldApi {
            dimension "apiLvl"
           //...
        }
        newApi {
            dimension "apiLvl"
            //...
        }
    }

Also, we have a library module named "abChat" without any flavors. What can I try to do to solve the problem?

like image 994
Gaket Avatar asked May 27 '17 15:05

Gaket


4 Answers

This issue is fixed and everything works fine in the Stable 3.0 version. If you still face this issue, that's because there is no fallback mechanism.

If your app includes a build type that the library doesn't then you will get this error. To fix this, you need to provide matchingFallbacks to your build type. Refer the Resolve build errors related to Dependency matching section in this documentation

In case of build types do the below, and if it's product flavors refer the documentation for migration.

buildTypes {
    release {
       //...
    }
    debug {
       //...
    }
    innerTest {
        //...
        matchingFallbacks = ['debug', 'release']
    }
}

and simply add your dependencies like below:

dependencies {
    implementation project(':abChat')
}
like image 149
Henry Avatar answered Oct 09 '22 11:10

Henry


This worked after a long research.

Replace:

implementation project(':abChat')

To:

implementation project(path: ':abChat', configuration: 'default')
like image 33
Shivakshi Chaudhary Avatar answered Oct 09 '22 11:10

Shivakshi Chaudhary


in your app

dependencies {
    debugImplementation project(':abChat')
    innerTestImplementation project(':abChat')
    releaseImplementation project(':abChat')
}

in your libary abChat

buildTypes {
    release {}
    debug{}
    innerTest{}
}
like image 19
Lincoln Sumauto Avatar answered Oct 09 '22 12:10

Lincoln Sumauto


Make sure you have the exact list(names) of build configurations (buildTypes) in all of your modules.

In my pre-3.0 setup, I was having only debug{} and release{} in all of my com.android.library modules. I added one more configuration similar to that of :app module. It builds fine for me.

like image 13
Vik Avatar answered Oct 09 '22 11:10

Vik