Gradle 4.0 Unable to find a matching configuration

AndroidGradleAndroid Gradle-Pluginbuild.gradle

Android Problem Overview


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?

Android Solutions


Solution 1 - Android

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

Solution 2 - Android

This worked after a long research.

Replace:

implementation project(':abChat')

To:

implementation project(path:':abChat', configuration: 'default')

Solution 3 - Android

in your app

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

in your libary abChat

buildTypes {
    release {}
    debug{}
    innerTest{}
}

Solution 4 - Android

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.

Solution 5 - Android

Check is it apply plugin: 'com.android.library' in build.gradle of your module, I just made this stupid mistake.

Solution 6 - Android

Removing this old configuration from build.gradle cleared the error

androidExtensions {
  experimental = true
}

Solution 7 - Android

Another possible solution is creating a build.gradle file of module project. To integrating an .aar file in your existing project, follow below mentioned method.

  1. Create a folder in your project. Mame it as sampleAarIntegration in same location where your "app" folder is available.

  2. Paste your sampleAar.aar file into sampleAarIntegration folder

  3. create gradle file inside sampleAarIntegration folder. Mame it as "build.gradle". paste below code in sampleAarIntegration:build.gradle file

    configurations.maybeCreate("default")
    artifacts.add("default", file('sampleAar.aar'))
    
  4. Add below line in your app:build.gradle

    implementation project(':sampleAarIntegration')
    
  5. Add below code into your settings.gradle file

    include ':app', ':sampleAarIntegration'
    
  6. sync project. You can see your module is integrated into your main project sucessfully.

Solution 8 - Android

Had same error and wasted my time. Here is the way to solve it. Focus on this line:

Could not resolve project : abChat.

abChat here is the name of project your app is either importing from saved package inside your app lib or downloading from web resource. So in my case it was another project:

could not resolve project MPChartLib

If your app uses already downloaded and saved data, in your gradle file it will be like this:

implementation project(':MPChartLib') // in this case the project name is MPChartlib, for your app it will be something else

If your app designed in a way to download and use that project data during build time it will be something like this:

implementation 'com.github.PhilJay:MPAndroidChart:v3.0.2' // // in this case the project name is MPChartlib, for your app it will be something else

The way to solve it,

  1. Option one - go to VS Code right click on the parent folder and select Find in Folder, search for the project name and see how it is imported and check, make sure that it still works - you have that project inside your project libs or the provided link is still works. Same way search option possible in Android Studio as well - Double click Shift button and enter search word for finding it anywhere in the project files.

  2. Option two - if you are familiar with the project structure check the build gradle file - check how it is imported, and make sure that the mentioned project is still available inside project libs or has working link for downloading during build process.

Solution 9 - Android

Run Your Android Studio as in Run as Administrator This was Working For me.. This Will Solve Your Problem Easily

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionGaketView Question on Stackoverflow
Solution 1 - AndroidHenryView Answer on Stackoverflow
Solution 2 - AndroidShivakshi ChaudharyView Answer on Stackoverflow
Solution 3 - AndroidLincoln SumautoView Answer on Stackoverflow
Solution 4 - AndroidVikView Answer on Stackoverflow
Solution 5 - AndroidSevenView Answer on Stackoverflow
Solution 6 - AndroidBrendan WeinsteinView Answer on Stackoverflow
Solution 7 - AndroidTaraView Answer on Stackoverflow
Solution 8 - AndroidElmarView Answer on Stackoverflow
Solution 9 - AndroidSahil ChoudharyView Answer on Stackoverflow