'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?



Solution 1:[1]

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:[2]

This worked after a long research.

Replace:

implementation project(':abChat')

To:

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

Solution 3:[3]

in your app

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

in your libary abChat

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

Solution 4:[4]

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:[5]

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

Solution 6:[6]

Removing this old configuration from build.gradle cleared the error

androidExtensions {
  experimental = true
}

Solution 7:[7]

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:[8]

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:[9]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Martin Marconcini
Solution 2 Shivakshi Chaudhary
Solution 3 Lincoln Sumauto
Solution 4
Solution 5 Seven
Solution 6 Brendan Weinstein
Solution 7
Solution 8 Elmar
Solution 9 Sahil Choudhary