Last week I wrote a short post about prompting users to send emails in React Native without using any native libraries. In it I talked a little bit about the technical debt involved in adding wrapper libraries to your projects. This is a bit of pain-point with React Native at the moment, so today I decided it would be interesting to write about an example that I encountered.
Recently I decided to upgrade the gradle wrapper and build tools version for one of my React Native projects(the Android side specifically). The default React Native project uses a pretty old version of gradle, which is quite slow, and I’m also trying to slowly work my way up to API 26 compatibility to satisfy the new impending requirements coming up later this year. Updating the gradle and build tools versions was actually easy enough in itself. Android Studio basically holds your hand through everything. But when I went to actually build and run my updated project on a device there were some issues – specifically with SDK Build Tools Versions.
SDK Build Tools Versions?
This particular project has a few native/wrapper libraries. They work great and most are well maintained but a lot of third party React Native libraries still target low build tools versions, so when I tried building my project the build failed and I got these kinds of errors:
The SDK Build Tools revision (23.0.1) is too low for project ‘:react-native-library’. Minimum required is 25.0.0
This is because I upgraded the build tools version in my actual project and there is a conflict between that and the build tools versions used in the external projects(libraries).
Making it Build
Well, there is a brute force solution of just going through each third party library you have and editing the build.gradle file so it targets a higher build tools version. If you only have one or two external libraries I suppose this could be okay, but it’s not very elegant. All the external library files are located in your node_modules, so if you ever decide to nuke it(or god forbird you run ‘react-native install’ for something) all of your changes will be wiped. You might forget about what you previously changed too and get dis-orientated. Thankfully there is another better solution, you just need to add something to your project-level build.gradle file:
Ideally you would add this below the allprojects node. Once you have this in your project-level build.gradle file, it will re-write all the compileSdkVersion/buildToolsVersion declarations for your external library projects and your project should compile if that was your only issue. And, as an added bonus you won’t have any issues if you wipe your node_modules and do a fresh re-install.