React Native

Boost the compilation time of your React Native or Android app with the latest Android build-tools

With the release of Gradle 3 and the great performance boost it comes with, it's very tempting to update like so:

Update the Gradle plugin so that it uses Gradle 3+

In your root ++code>build.gradle++/code>, update the Gradle plugin so that it uses Gradle 3+:

++pre>...
dependencies {
   classpath 'com.android.tools.build:gradle:2.3.0'
...++/pre>

Update the build tools to the latest (25)

In your ++code>app/build.gradle++/code>, update the build tools to the latest (25), because it's mandatory to support Gradle 3+:

++pre>...
android {
   compileSdkVersion 23
   buildToolsVersion '25.0.2'
...++/pre>

Replace it

Optionaly, if you have set ++code>distributionUrl++/code> in your ++code>gradle/wrapper/gradle-wrapper.properties++/code> file, you may want to replace it with:

++pre>++code>distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-bin.zip
++/code>++/pre>

Sadly, you'll very much likely encounter this sort of error: ++code>The SDK Build Tools revision (23.0.1) is too low for project ':react-native-vector-icons'. Minimum required is 25.0.0++/code>. That's because one of your dependency (here, react-native-vector-icons) uses an old build tools version.

The process of updating the dependency (make a PR, be reviewed, be merged, and be published) can take a long time. Fortunately, you can overwrite the build tools version of your dependencies. To do so, copy and paste in your root ++code>build.gradle++/code>:

++pre>ext {
   compileSdkVersion = 23
   buildToolsVersion = '25.0.2'
}

subprojects { subproject ->
   afterEvaluate{
       if((subproject.plugins.hasPlugin('android') || subproject.plugins.hasPlugin('android-library'))) {
           android {
               compileSdkVersion rootProject.ext.compileSdkVersion
               buildToolsVersion rootProject.ext.buildToolsVersion
           }
       }
   }
}++/pre>

And in your ++code>app/build.gradle++/code>, replace:

++pre>...
android {
   compileSdkVersion rootProject.ext.compileSdkVersion
   buildToolsVersion rootProject.ext.buildToolsVersion
...++/pre>

Congratulations, you can now enjoy Gradle 3 build against the latest version of Android build-tools, thus boosting your compilation time. For example, in one of our React Native application, it now takes only 10 seconds when no changes were made!

Développeur mobile ?

Rejoins nos équipes