81

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?

Gaket
  • 6,533
  • 2
  • 37
  • 67

10 Answers10

94

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')
}
Martin Marconcini
  • 26,875
  • 19
  • 106
  • 144
Henry
  • 17,490
  • 7
  • 63
  • 98
56

This worked after a long research.

Replace:

implementation project(':abChat')

To:

implementation project(path: ':abChat', configuration: 'default')
Boken
  • 4,825
  • 10
  • 32
  • 42
  • 4
    I got this error =>> A problem occurred evaluating project ':app'. > Could not find method project() for arguments [{configuration=default}, :swipecardview] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler. @shivakshi-chaudhary – hugerde Nov 29 '18 at 10:09
  • 6
    This do not work for me, at first glance - it works, build runs with no error, but when I try to import class from the library, it ask me to import the library ... it seems the library is not imported ... – Ivan Kolev Apr 14 '19 at 18:56
  • But in which file shall I make this change? – Deepak Thakur Apr 17 '19 at 10:47
  • 1
    This doesn't work anymore since android build tools 3.5.x for me. Does anyone know what changed in 3.5.x and how to fix it again? – Hollerweger Oct 23 '19 at 17:22
  • 6
    not working in my case, getting this error - Unable to find a matching configuration of project :foliolibrary: - None of the consumable configurations have attributes. – s.j Dec 10 '19 at 13:16
  • 1
    not work for me :( it compiles, but when running, it gives me NoClassDefFoundError! – ch271828n Mar 30 '21 at 03:31
  • Not working for me. Same as @IvanKolev problem. Any solution for the imports? – Shubham AgaRwal Apr 02 '23 at 19:01
19

in your app

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

in your libary abChat

buildTypes {
    release {}
    debug{}
    innerTest{}
}
Lincoln Sumauto
  • 219
  • 2
  • 3
13

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.

Vik
  • 347
  • 1
  • 12
  • It not depends on number of buildTypes, but on names (missing buildTypes in modules). Of course when you put same types to all modules, it will work... But it's not sollution. Sollution will be when Google fix: https://issuetracker.google.com/issues/62170415#comment12 variant 4. – mtrakal Jun 14 '17 at 10:13
  • That's what I meant. I've edited to show "exact names" instead of "exact number" – Vik Jun 20 '17 at 22:06
  • 5
    This worked but is quite annoying that you have to do this. Also wish it was documented somewhere. like basically all gradle issues... seriously lacking documentation – ClayHerendeen Sep 18 '17 at 18:29
  • Thanks guys, its helped fix an issue I was having. I had 3 build types in my app module. When I build my "new" module it would start to throw errors because it doesnt have the buildtypes in my app module. Ive put them into the "new" module and that works fine. But thats not a good fix though right? Like module should have 0 dependencies on its app module? – aidanmack Nov 14 '17 at 15:47
6

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

Seven
  • 203
  • 3
  • 7
  • Thanks, but it was not the problem in our case. Accepted answer solved it. – Gaket Dec 21 '18 at 02:09
  • 1
    Thank you, that saved my day. I imported a project which used "apply plugin: 'com.android.application" in build.gradle and this the sync failed. Changed it to 'com.android.library' and it works like a charm. – Luigi_Papardelle Sep 23 '19 at 09:03
1

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. Name 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. Name 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', ':seedFab'
    
  6. sync project. You can see your module is integrated into your main project sucessfully.

Tara
  • 2,598
  • 1
  • 21
  • 30
0

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.

Elmar
  • 2,235
  • 24
  • 22
0

For Gradle 7.1.x versions and above, If you have tried matchingFallbacks and other mentioned solutions and still issue persists, try downgrading to 7.0.4

Max Droid
  • 924
  • 9
  • 10
-1

Removing this old configuration from build.gradle cleared the error

androidExtensions {
  experimental = true
}
Brendan Weinstein
  • 6,938
  • 7
  • 25
  • 29
-2

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

Sahil Choudhary
  • 181
  • 1
  • 7