Fixing "SDK Build Tools is Too Low" in React Native
On this page
One of the most annoying things that can happen while developing a React Native app is the dreaded A problem occurred configuring project ':app' error, immediately followed by a more specific The SDK Build Tools revision (xx.x.x) is too low for project ':your-react-native-dependency'.
When the error occurs
This typically happens in one of these scenarios:
- Running
react-native run-androidafter updating native dependencies - Running
yarn, which resets any manual modifications you made innode_modules - Linking native modules, either automatically (
react-native link) or manually
Why existing fixes are temporary
Most tutorials out there propose either manually editing the build.gradle files of each problematic dependency inside node_modules, or worse, downgrading to an older (and slower) version of Gradle.
The problem? These fixes get wiped out every time you run your package manager or update dependencies. You’d have to repeat the process all over again.
The permanent solution: Gradle’s afterEvaluate
Instead of fighting this battle manually every time, we can leverage the Gradle build tool scripting language directly. Gradle’s Project API has a method called afterEvaluate, which, quoting the official docs, “adds a closure to be called immediately after this project has been evaluated.” Think of it as React’s componentDidMount on steroids.
The right place to call this method is in your android/build.gradle file, inside the subprojects {} section.
The fix
First, make sure you have your SDK versions defined as ext variables in the buildscript block of your android/build.gradle:
buildscript {
ext {
compileSdkVersion = 26
buildToolsVersion = "26.0.1"
}
// ... repositories and dependencies
} Then, add the following subprojects block in the same file:
subprojects {
afterEvaluate { project ->
if (project.hasProperty("android")) {
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
}
}
}
} By adding this script, you basically delegate to Gradle the task of overwriting the compileSdkVersion and buildToolsVersion entries in the android property of every dependency’s build.gradle file, automatically, every single time.
Wrapping up
Simple as pie. I personally love when a tedious issue can be fixed in a handful of lines of code. No more manual edits, no more downgrading Gradle, no more repeating yourself after every yarn install.