After adding or updating a dependency in Android Studio, you may see the error “Dependency ‘~’ requires libraries and applications that depend on it to compile against version ~ or later” and the project may fail to build.
- Error message
- Common situations where this occurs
- Check 1: Confirm the required version shown in the error
- Solution 1: Increase compileSdk
- Solution 2: Install the required Android SDK Platform
- Solution 3: Revert the dependency to a compatible version
- Solution 4: Align compileSdk across multiple modules
- Difference between compileSdk, minSdk, and targetSdk
- If the error still remains
- Summary
Error message
Dependency '~' requires libraries and applications that depend on it to compile against version ~ or later.
This error occurs when the app’s compileSdk is lower than the compile SDK version required by a dependency. This is different from minSdk and targetSdk, so the first setting to check is compileSdk.
Common situations where this occurs
- You updated AndroidX, Material Components, or another library to a newer version.
- You added a new dependency and its AAR metadata requires a higher Compile SDK.
- You opened an older project with a newer version of Android Studio or the Android Gradle Plugin.
- In a multi-module project, only some modules still use a lower
compileSdk.
Check 1: Confirm the required version shown in the error
First, open Build Output and check which dependency requires which Compile SDK version. For example, if a library requires API 35 or later while the app is compiled against API 34, the versions do not match.
Write down the dependency name and the required version before changing settings. This makes it easier to isolate the cause.
Solution 1: Increase compileSdk
In the module-level build.gradle.kts, change compileSdk inside the android block to the value required by the library or higher.
android {
compileSdk = 35
}
For Groovy syntax, configure it as follows.
android {
compileSdk 35
}
After changing the setting, run Gradle Sync and build the project again.
Solution 2: Install the required Android SDK Platform
If you increase compileSdk but the corresponding SDK Platform is not installed locally, a different error can occur. Open SDK Manager in Android Studio and install the Android SDK Platform for the API level you configured.
Solution 3: Revert the dependency to a compatible version
If you cannot increase compileSdk immediately, you can revert the dependency to an older compatible version.
dependencies {
implementation("com.example:library:previous-compatible-version")
}
However, keeping an older version pinned for a long time may prevent you from receiving bug fixes or security updates. As a long-term solution, it is preferable to update compileSdk appropriately.
Solution 4: Align compileSdk across multiple modules
In projects that include the app module, library modules, or feature modules, check the compileSdk value in every Android module. If only one module uses an older value, dependency validation may fail.
Difference between compileSdk, minSdk, and targetSdk
compileSdk determines which Android APIs are available at compile time. minSdk specifies the minimum Android version on which the app can run, while targetSdk indicates the Android version for which the app is designed and tested.
Increasing compileSdk does not by itself end support for older Android devices. The minimum supported version is mainly determined by minSdk.
If the error still remains
If the same error remains after Gradle Sync, review the dependency shown in Build Output and confirm again which library requires the higher Compile SDK. If necessary, inspect the dependency tree as well.
./gradlew app:dependencies
On Windows, run the Gradle Wrapper as follows.
gradlew.bat app:dependencies
Summary
If “Dependency ‘~’ requires libraries and applications that depend on it to compile against version ~ or later” appears, check whether the Compile SDK required by the dependency matches the app’s compileSdk. The basic solution is to update compileSdk to the required version or higher, install the necessary SDK Platform, and run Gradle Sync. If you cannot update immediately, revert the dependency to a compatible version.
