An Android module cannot find a matching variant of the module it depends on
Unable to find a matching configurationShort answer
Gradle matches your app's variant to a variant of every module it depends on. When a direct match does not exist it stops and names the project it could not resolve. Find out whether the library lacks a build type, lacks a product flavor, has a flavor dimension your app does not have, or applies no plugin at all.
Fix it fast
1Find out which cause you have
Find out which variant of the app fails, then print its dependency tree and read where the library module shows up or is marked as failed. Replace stagingRuntimeClasspath with the runtime classpath of the variant that failed (for example debugRuntimeClasspath).
./gradlew :app:dependencies --configuration stagingRuntimeClasspath2Match what you see, then jump to its fix
- 1
Only one build type of the app fails, for example a custom staging type, while debug and release buildThe app has a build type that the library does not haveFix - 2
Only the flavors you added in the app fail, and both modules declare the same flavor dimensionThe app has a product flavor that the library does not have in the same dimensionFix - 3
The library declares flavors (for example minApi18 and minApi23), and your app has no flavor dimension with that nameThe library has a flavor dimension that the app does not haveFix - 4
No matching variant of project :producer was found, followed by the line No variants exist.The module you depend on applies no plugin, so it has no variantsFix
- 1
What does the error look like?
Unable to find a matching configurationCould not resolve project :mylibrary.No matching variant of project :producer was found.No variants exist.
Cause 1 of 4
The app has a build type that the library does not have
1Check
Compare the build types in the app with the ones in the library. The Android documentation says there is no problem when the library has an extra build type, because the plugin never requests it. The problem is an app build type the library lacks.
grep -n -A12 "buildTypes" app/build.gradle* mylibrary/build.gradle*2Fix
Tell the app which library build type to use instead. The plugin takes the first fallback that the library offers.
// app/build.gradle.kts
android {
buildTypes {
create("staging") {
matchingFallbacks += listOf("debug", "release")
}
}
}3Verify
Build the failing variant.
./gradlew :app:assembleStagingConfirmed by developer.android.com
Cause 2 of 4
The app has a product flavor that the library does not have in the same dimension
1Check
List the flavors of the shared dimension in both modules. A library with demo and paid flavors cannot answer a request for free.
grep -n -B2 -A14 "productFlavors" app/build.gradle* mylibrary/build.gradle*2Fix
Set matchingFallbacks on the app's flavor, not in defaultConfig. The Android documentation says to configure fallbacks for a flavor inside productFlavors.
// app/build.gradle.kts
android {
flavorDimensions += "tier"
productFlavors {
create("free") {
dimension = "tier"
matchingFallbacks += listOf("demo", "trial")
}
create("paid") {
dimension = "tier"
}
}
}3Verify
Build a variant of the flavor that failed.
./gradlew :app:assembleFreeDebugConfirmed by developer.android.com
Cause 3 of 4
The library has a flavor dimension that the app does not have
1Check
Look for flavorDimensions in the library that do not exist in the app. The plugin cannot choose between minApi18 and minApi23 of the library on its own.
grep -n "flavorDimensions" app/build.gradle* mylibrary/build.gradle*2Fix
Name the dimension and the flavor to use in the app's defaultConfig with missingDimensionStrategy. The first flavor listed is the preferred one, the rest are fallbacks.
// app/build.gradle.kts
android {
defaultConfig {
missingDimensionStrategy("minApi", "minApi18", "minApi23")
}
}3Verify
Sync the project and build the app.
./gradlew :app:assembleDebugConfirmed by developer.android.com
Cause 4 of 4
The module you depend on applies no plugin, so it has no variants
1Check
Open the build file of the module named in the message. Gradle 8.9 release notes say this message appears when a project declares no variants, for instance because it applies no JVM plugin.
cat mylibrary/build.gradle*
grep -n "include" settings.gradle*2Fix
Apply the plugin that matches the module. For an Android library that is com.android.library; the Android documentation shows how to change an app module into a library module and then sync.
// mylibrary/build.gradle.kts
plugins {
id("com.android.library")
}3Verify
Sync, then build the app module that uses it.
./gradlew :app:assembleDebugConfirmed by docs.gradle.org
How do I stop it coming back?
- Keep build type names the same in every module of a project, or add matchingFallbacks the day you add a custom one.
- Keep flavor dimension names and flavor names the same across the app and its library modules.
- Run a full assemble of every variant on CI, so a missing match shows up in a pull request.
- Declare each module's plugin in its own build file and keep the module list in settings.gradle in step.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Mobile apps
adb cannot start because something already holds its port
adb start-server failed
The adb server must bind local TCP port 5037, and every adb client talks to it there.
2 causes, each with a fixMobile apps
The phone shows as unauthorized and Android Studio will not run the app
adb devices lists the phone but Android Studio cannot deploy to it
An unauthorized phone means it has not trusted this computer's RSA key.
3 causes, each with a fixMobile apps
Android Studio cannot pair the phone over Wi-Fi
The Pair devices over Wi-Fi dialog lists no device
Wireless pairing needs the phone on Android 11 or higher and on the same Wi-Fi network as the computer, with current Platform-Tools.
4 causes, each with a fixMobile apps
adb cannot connect to its daemon or start the server
* daemon started successfully *
The adb server is a background process on your computer that listens on TCP port 5037.
2 causes, each with a fixMobile apps
adb prints 'server version doesn't match this client; killing...'
adb server version doesn't match this client; killing...
adb runs a background server, and every adb command is a client.
3 causes, each with a fixMobile apps
adb tcpip 5555 fails because no device is found
adb: more than one device/emulator
adb tcpip only works while the device is attached and listed by adb, because it tells the phone to start listening on port 5555.
4 causes, each with a fix