Search code examples
androidreact-nativegradlebuild.gradlebuild-tools

Compile project dependency with build tool version - react native


In react-native project app/build.gradle is defined as follows. The root project uses a build tool version of 26.0.2 while the dependencies has various versions.

dependencies {
   ...
   compile project(':react-native-config')
   ...
}

Is there a way that I could define the buildToolVersion while defining the dependencies where all gradle files of the project would normalized with a same buildToolVersion?


Solution

  • Somehow I figured out a way. By adding following snippet to the root build.gradle it can be easily done.

    subprojects {
        ...
        afterEvaluate { subproject ->
            if ((subproject.plugins.hasPlugin('android') || 
                subproject.plugins.hasPlugin('android-library'))) {
                android {
                    buildToolsVersion "26.0.2"
                }
            }
        }
    
    }
    

    During build, it change each of android dependency version into the required.