react-native: Included build node_modules/@react-native/gradle-plugin does not exists

Description

Im trying to upgrade from 0.65.1 to 0.71.4 and I am encountering a problem where Gradle cannot find the gradle-plugin.

I am using yarn for installation.

I have triple checked that all changes are correct from the upgrade helper.

My react-native node package.

  • node_modules
      • Assets
      • normalize-color
      • polyfills — no gradle-plugin folder here

Steps I have tried. Removing caches: rm -r $HOME/.gradle/caches
Remove and reinstall packages rm -rf node_modules rm -rf yarn.lock yarn install

React Native Version

0.71.4

Output of npx react-native info

System:
    OS: macOS 13.2.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 64.20 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.15.0 - /usr/local/bin/node
    Yarn: 1.22.18 - /opt/homebrew/bin/yarn
    npm: 8.5.5 - /usr/local/bin/npm
    Watchman: 2022.08.15.00 - /opt/homebrew/bin/watchman
  Managers:
    CocoaPods: 1.11.3 - /opt/homebrew/bin/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 22.2, iOS 16.2, macOS 13.1, tvOS 16.1, watchOS 9.1
    Android SDK:
      API Levels: 30
      System Images: android-30 | Google Play ARM 64 v8a
      Android NDK: Not Found
  IDEs:
    Android Studio: 2022.1 AI-221.6008.13.2211.9619390
    Xcode: 14.2/14C18 - /usr/bin/xcodebuild
  Languages:
    Java: 11.0.15 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: ^11.0.0 => 11.0.0 
    react: 18.2.0 => 18.2.0 
    react-native: 0.71.4 => 0.71.4 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Steps to reproduce

Any of these steps fail the same ways

./gradlew clean ./gradlew cleanBuildCache npx react-native run-android

Snack, code example, screenshot, or link to a repository

This is my package.json

{
  "name": "XXXXX",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android-local": "set ENVFILE=.env.local && react-native run-android",
    "android-dev": "ENV=dev react-native run-android",
    "ios-local": "react-native run-ios --scheme=local",
    "ios-dev": "react-native run-ios --scheme=dev",
    "start": "react-native start --reset-cache",
    "test": "jest",
    "lint": "eslint ."
  },
  "dependencies": {
    "@gorhom/bottom-sheet": "^4",
    "@react-native-async-storage/async-storage": "^1.15.5",
    "@react-native-community/cli": "^11.0.0",
    "@react-native-community/cli-platform-android": "^11.0.0",
    "@react-native-community/cli-platform-ios": "^11.0.0",
    "@react-native-community/geolocation": "^2.0.2",
    "axios": "^0.21.4",
    "eslint-plugin-import": "^2.24.1",
    "install": "^0.13.0",
    "jwt-decode": "^3.1.2",
    "react": "18.2.0",
    "react-native": "0.71.4",
    "react-native-axios-jwt": "^1.1.0",
    "react-native-config": "^1.4.4",
    "react-native-device-info": "^8.3.3",
    "react-native-geolocation-service": "^5.3.0-beta.3",
    "react-native-gesture-handler": "^2.9.0",
    "react-native-maps": "^0.29.3",
    "react-native-progress": "^5.0.0",
    "react-native-reanimated": "^3.0.2",
    "react-native-svg": "^12.1.1"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0",
    "@babel/preset-env": "^7.20.0",
    "@babel/runtime": "^7.20.0",
    "@react-native-community/eslint-config": "^3.2.0",
    "@tsconfig/react-native": "^2.0.2",
    "@types/jest": "^29.2.1",
    "@types/react": "^18.0.24",
    "@types/react-test-renderer": "^18.0.0",
    "babel-jest": "^29.2.1",
    "eslint": "^8.19.0",
    "jest": "^29.2.1",
    "metro-react-native-babel-preset": "0.73.8",
    "prettier": "^2.4.1",
    "react-test-renderer": "18.2.0",
    "typescript": "4.8.4"
  },
  "jest": {
    "preset": "react-native"
  }
}

android/build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext {
        buildToolsVersion = "33.0.0"
        minSdkVersion = 21
        compileSdkVersion = 33
        targetSdkVersion = 33

        // We use NDK 23 which has both M1 support and is the side-by-side NDK version from AGP.
        ndkVersion = "23.1.7779620"
    }
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:7.3.1")
        classpath("com.facebook.react:react-native-gradle-plugin")
    }
}

android/app/build.gradle

apply plugin: "com.android.application"
apply plugin: "com.facebook.react"
apply from: project(":react-native-config").projectDir.getPath() + "/dotenv.gradle"
import com.android.build.OutputFile
project.ext.envConfigFiles = [
  release: ".env.production",
  local: ".env.local",
  development: ".env.development",
]

react {
    
}
def enableSeparateBuildPerCPUArchitecture = false

def enableProguardInReleaseBuilds = false

def jscFlavor = 'org.webkit:android-jsc:+'

def reactNativeArchitectures() {
    def value = project.getProperties().get("reactNativeArchitectures")
    return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
}

android {
    ndkVersion rootProject.ext.ndkVersion
    compileSdkVersion rootProject.ext.compileSdkVersion
    namespace "com.XXX"
    defaultConfig {
        applicationId "com.XXX"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1.0"
        resValue "string", "build_config_package", "com.XXX"
        manifestPlaceholders = [label: 'XXX']

    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include (*reactNativeArchitectures())
        }
    }
    signingConfigs {
        debug {
            storeFile file('debug.keystore')
            storePassword 'android'
            keyAlias 'androiddebugkey'
            keyPassword 'android'
        }
    }
    buildTypes {
        debug {
            signingConfig signingConfigs.debug
            matchingFallbacks = ['debug', 'release']
        }
        release {
            // Caution! In production, you need to generate your own keystore file.
            // see https://reactnative.dev/docs/signed-apk-android.
            signingConfig signingConfigs.debug
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
        local {
            initWith debug
            applicationIdSuffix ".local"
            manifestPlaceholders = [label: 'XXX Local']
        }
        development {
            initWith debug
            applicationIdSuffix ".development"
            manifestPlaceholders = [label: 'XXX Dev']
        }
    }

    // applicationVariants are e.g. debug, release
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            // For each separate APK per architecture, set a unique version code as described here:
            // https://developer.android.com/studio/build/configure-apk-splits.html
            // Example: versionCode 1 will generate 1001 for armeabi-v7a, 1002 for x86, etc.
            def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
            def abi = output.getFilter(OutputFile.ABI)
            if (abi != null) {  // null for the universal-debug, universal-release variants
                output.versionCodeOverride =
                        defaultConfig.versionCode * 1000 + versionCodes.get(abi)
            }

        }
    }
}

dependencies {
    implementation("com.facebook.react:react-android")

    implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.0.0")
    //Location
    implementation "com.google.android.gms:play-services-location:16.0.0"
    implementation 'com.google.android.gms:play-services-base:17.2.1'
    implementation 'com.google.android.gms:play-services-maps:17.0.0'
    //config constants
    implementation project(':react-native-config')
    
    debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}")
    debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
        exclude group:'com.squareup.okhttp3', module:'okhttp'
    }

    debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}")

    if (hermesEnabled.toBoolean()) {
        implementation("com.facebook.react:hermes-android")
    } else {
        implementation jscFlavor
    }
}

apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)

Settings.gradle

rootProject.name = 'XXX'
include ':react-native-config'
project(':react-native-config').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-config/android')
include ':@react-native-community_geolocation'
project(':@react-native-community_geolocation').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-community/geolocation/android')
include ':react-native-location'
project(':react-native-location').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-location/android')
include ':react-native-config'
project(':react-native-config').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-config/android')
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
include ':app'
includeBuild('../node_modules/@react-native/gradle-plugin')

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 3
  • Comments: 21 (3 by maintainers)

Most upvoted comments

For react native 0.71, the package is located inside node_modules/react-native-gradle-plugin.

includeBuild(‘…/node_modules/@react-native/gradle-plugin’)

This is wrong, you will have to use:

includeBuild('../node_modules/react-native-gradle-plugin')

For React Native 0.72+ instead the correct path is the one you shared originally.

includeBuild('../node_modules/@react-native/gradle-plugin')

Also where have you copied this from @pr0tonion ?

For react native 0.71, the package is located inside node_modules/react-native-gradle-plugin.

includeBuild(‘…/node_modules/@react-native/gradle-plugin’)

This is wrong, you will have to use:

includeBuild('../node_modules/react-native-gradle-plugin')

Also where have you copied this from @pr0tonion ?

The updated path/namespace is

includeBuild('../node_modules/@react-native/gradle-plugin')

A workaround for pnpm is to point to library inside .pnpm in my case, a mono repo, in the parent folder. includeBuild('../../node_modules/.pnpm/@react-native+gradle-plugin@0.72.11/node_modules/@react-native/gradle-plugin')

@cortinico I am on react 0.72.3 I have used this in build.gradle

includeBuild('../node_modules/@react-native/gradle-plugin')

Still getting the error "Could not read script 'node_modules/@react-native/gradle-plugin' as it is a directory"

For react native 0.71, the package is located inside node_modules/react-native-gradle-plugin.

includeBuild(‘…/node_modules/@react-native/gradle-plugin’)

This is wrong, you will have to use:

includeBuild('../node_modules/react-native-gradle-plugin')

For React Native 0.72+ instead the correct path is the one you shared originally.

includeBuild('../node_modules/@react-native/gradle-plugin')

Also where have you copied this from @pr0tonion ?

I’m using RN 0.72+ and pnpm and I only see 2 symlinks in this folder: image

does anyone knows how to fix this using pnpm?

npm i react-native-gradle-plugin

in my case I install it with npm

Same problem here with pnpm and RN 0.72+ …

@geeron updated

Awesome @ausshadu, that worked! @cortinico Are you able to edit your comment with this new info, since you have the most thumbs-up in this thread, it is easy to get confused 😃

Hi there, having the exact same issue with upgrade from 0.62.1 to 0.69.1

None of the previous solutions are working for me.

Even when I do “./gradlew clean” I got the same :

  • What went wrong: Execution failed for task ‘:react-native-gradle-plugin:compileKotlin’.

Compilation error. See log for more details

I followed the react native updated plus tried every previous solutions.

Any ideas ?

@Suresh-Naragonda You can just remove that “includeBuild” line completely. I saw this solution from the react-native-upgrade-helper and it worked fine for me.

For react native 0.71, the package is located inside node_modules/react-native-gradle-plugin.

includeBuild(‘…/node_modules/@react-native/gradle-plugin’)

This is wrong, you will have to use:

includeBuild('../node_modules/react-native-gradle-plugin')

For React Native 0.72+ instead the correct path is the one you shared originally.

includeBuild('../node_modules/@react-native/gradle-plugin')

Also where have you copied this from @pr0tonion ?

Hi @cortinico, my project have react native 0.72.4, but it is showing the same error, As I noticed my node_modules doesn’t contain that folder which you specified to add instead I found react-native-gradle-plugin inside node_modules

@cortinico I was using the upgrade helper. But I see now that I clearly missed that part… Thank you so much! I have been looking at this problem for a week and have somehow overlooked it the 4 times I checked