Resolving AppCompat Version Conflicts in Android Development

Today I wanna talk briefly about a problem that can be a pain in the ass to solve: conflicts on AppCompat version.

Well, if you are working on a well-structured project where there are pipelines for CI/CD and it tests the build of the application every time you generate a PR, then you’re good. You will have some options to solve it, like removing the dependencies that rely on the conflicting AppCompat version, downgrading those dependencies so none of them will cause conflicts, or even using brute-force solutions if you need to.

Talking about brute-force solutions, that’s what I want to explain here. If you are in the opposite situation from what I described above, this post may save your ass. I need to alert you that this is not a fancy solution, but it will make your app work again. So, let’s do this.

The Brute Force Solution

The thing is, making your app or lib conform to a specific version of appcompat can’t be enough sometimes. That happens because the dependencies of your project can use a specific appcompat version that will cause conflict. It gets worse when you try to check the dependencies but the libs you’re using are protected, making the command fail.

So if you don’t have control over how dependencies are managed and conflicts are making your build break, you can force Gradle to use a specific version of AppCompat, for all the dependencies and sub-dependencies. Here’s how:

Step 1: Force a Specific Version in android/build.gradle

Change your android/build.gradle to enforce AppCompat 1.6.1 for all dependencies:

allprojects {
    repositories {
        google()
        mavenCentral()
    }
    configurations.all {
        resolutionStrategy.eachDependency { details ->
            if (details.requested.group == 'androidx.appcompat' && details.requested.name == 'appcompat') {
                details.useVersion '1.6.1'
            }
            if (details.requested.group == 'androidx.appcompat' && details.requested.name == 'appcompat-resources') {
                details.useVersion '1.6.1'
            }
        }
    }
}

What this does:

  • The resolutionStrategy.eachDependency block checks every dependency in the project and ensures that any reference to androidx.appcompat or appcompat-resources uses version 1.6.1.
  • The force directive ensures that no other version of AppCompat can override this decision.
  • This guarantees consistency, preventing mismatched versions from causing conflicts.

Step 2: Update app/build.gradle Dependencies

Even though we’ve forced the version in Step 1, we still need to explicitly declare AppCompat and other related dependencies in our app’s build.gradle file to ensure they are correctly linked to our project.

Update your app/build.gradle file as follows:

dependencies {
    implementation 'androidx.appcompat:appcompat:1.6.1'
    implementation 'androidx.multidex:multidex:2.0.1'
    implementation 'androidx.core:core-ktx:1.10.1'
}

Why this is important:

  • By explicitly declaring AppCompat as a dependency, we ensure our project directly references the enforced version (1.6.1).
  • The multidex dependency is necessary for projects with a large number of methods, preventing the Dex limit issue.
  • core-ktx provides Kotlin extensions for AndroidX, improving development experience and performance.

Final Thoughts

This is a brute-force approach and should be used only when necessary. The best long-term solution is to properly manage dependencies, align versions, and maintain a structured development workflow. But if you’re in a hurry and need your build to work ASAP, this might be the fix you need.

Have you faced AppCompat conflicts before? Share your experiences and solutions in the comments!

Leave a comment

Blog at WordPress.com.

Up ↑