Emoji error! Using the latest Compose with compileSDK < 34

Emoji error! Using the latest Compose with compileSDK < 34

Wanting to use the latest versions of Compose, but your app compileSdk is falling behind? I’ve been there! If you have a compileSdk < 34 but want to use Compose version > 1.5.0 you’ll come across a horrid build error. Let’s fix that!

The error is question is this:

An issue was found when checking AAR metadata:

  1.  Dependency 'androidx.emoji2:emoji2:X.X.X' requires libraries and applications that depend on it to compile against version 34 or later of the Android APIs.

:app is currently compiled against android-33.

Recommended action: Update this project to use a newer compileSdk of at least 34, for example 34.

Note that updating a library or application's compileSdk (which allows newer APIs to be used) can be done separately from updating targetSdk (which opts the app in to new runtime behavior) and minSdk (which determines which devices the app can be installed on).

Compose dependencies with a version > 1.5.0 or BOM version 2023.08.00 pull in transitive dependencies that themselves depend on some newer features in the Android SDK.

The typical culprit is the androidx.emoji2 emoji libraries. If you see these strange errors and are thinking, I don’t even use those dependencies! Then this is the solution for you.

To avoid having to bump your compileSdk version (even though you should bump it, but there are always other forces in play), then you can declare to Gradle, how to force a lower version of these transitive dependencies.

Solution

For Compose it works as so.

In the build.gradle file that is raising the issues:

// Whilst the compileSdk is < 34
// force the version of these dependencies
// we don't use them, but they are pulled in by Compose project.configurations.configureEach {
  resolutionStrategy {
    force("androidx.emoji2:emoji2-views-helper:1.3.0")
    force("androidx.emoji2:emoji2:1.3.0")
  }
}

If you need to do it for all projects, or multiple projects then there are a few choices, you should use your projects preferred Gradle method for multi-project configuration. Here is one of the quicker solutions:

subprojects {
  ...
  project.configurations.configureEach {
    ...
    // Whilst the compileSdk is < 34
    // force the version of these dependencies
    // we don't use them, but they are pulled in by the compose dependencies
    resolutionStrategy {
      force("androidx.emoji2:emoji2-views-helper:1.3.0")
      force("androidx.emoji2:emoji2:1.3.0")
    }
  }
}

The above forces the version of emoji2 to be version 1.3.0 (where version 1.4.0 and above is giving issues).

Official resolutionStrategy API here.

Official resolutionStrategy docs here.

That’s it!

Until you increase your compileSdk version the above resolutionStrategy should allow you to use the latest version of Compose in your app.

Any questions, you can find me on:

Threads @Blundell_apps

Leave a Reply

Your email address will not be published. Required fields are marked *