Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where's rootProject.ext in React Native project

In my React Native project, I need to set a few things like minSdkVersion, targetSdkVersion, etc. In the build.gradle file, I see references to rootProject.ext section which appears to be a central location for settings. I ran a search in the project but couldn't find rootProject.ext anywhere except in this section of build.gradle. I can "cheat" and put actual values in there and it works but I'd like to know where rootProject.ext is. For example, where's the compileSdkVersion or minSdkVersion coming from in the following code?

android {
    compileSdkVersion rootProject.ext.compileSdkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        applicationId "com.ingridtm"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1.0"
    }
}

P.S. This is out of a regular React Native project -- targeting 0.63.4 -- that is created with npx react-native init myproject. So I changed nothing in build.gradle up to this point.

like image 898
Sam Avatar asked Aug 06 '26 01:08

Sam


1 Answers

You can place these root settings in your project-level build.gradle file (at android/build.gradle), in the buildscript section:

buildscript {
    ext {
        buildToolsVersion = "29.0.2"
        ...
    }
like image 56
Marek Lisik Avatar answered Aug 07 '26 15:08

Marek Lisik