facebook / react-native

A framework for building native applications using React
https://reactnative.dev
MIT License
119.27k stars 24.35k forks source link

Could not find com.facebook.react:react-native-gradle-plugin:. #37953

Closed nikit-psl closed 1 year ago

nikit-psl commented 1 year ago

New Version

0.71.11

Old Version

0.67.5

Build Target(s)

While building for Android

Output of react-native info

System:
    OS: macOS 13.1
    CPU: (8) arm64 Apple M1
    Memory: 106.58 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 18.13.0 - ~/.nvm/versions/node/v18.13.0/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v14.20.0/bin/yarn
    npm: 8.19.3 - ~/.nvm/versions/node/v18.13.0/bin/npm
    Watchman: 2023.01.09.00 - /opt/homebrew/bin/watchman
  Managers:
    CocoaPods: 1.11.3 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 22.2, iOS 16.2, macOS 13.1, tvOS 16.1, watchOS 9.1
    Android SDK: Not Found
  IDEs:
    Android Studio: 2021.2 AI-212.5712.43.2112.8609683
    Xcode: 14.2/14C18 - /usr/bin/xcodebuild
  Languages:
    Java: 11.0.17 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 18.2.0 => 18.2.0 
    react-native: 0.71.11 => 0.71.11 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Issue and Reproduction Steps

While building the app for Android after upgrading React Native I'm getting this error

Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'App'.
> Could not determine the dependencies of null.
   > Could not resolve all task dependencies for configuration ':classpath'.
      > Could not find com.facebook.react:react-native-gradle-plugin:.
        Required by:
            project :

Thing's I've tried


Files -

package.json

{
  "name": "App",
  "version": "1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "start": "react-native start",
    "test": "jest",
    "lint": "eslint .",
    "clean": "cd android && ./gradlew clean && cd ..",
    "build": "cd android && ./gradlew clean && ./gradlew bundleRelease && cd .. && react-native run-android --variant=release",
    "build:prod": "cd android && ./gradlew clean && ./gradlew app:bundleRelease"
  },
  "dependencies": {
    "@datadog/mobile-react-native": "^1.0.0-rc5",
    "@datadog/mobile-react-navigation": "^1.0.0-rc5",
    "@invertase/react-native-apple-authentication": "^2.2.2",
    "@ptomasroos/react-native-multi-slider": "^2.2.0",
    "@react-native-clipboard/clipboard": "^1.8.5",
    "@react-native-community/art": "^1.2.0",
    "@react-native-community/async-storage": "^1.8.1",
    "@react-native-community/datetimepicker": "^6.1.3",
    "@react-native-community/masked-view": "^0.1.7",
    "@react-native-community/push-notification-ios": "^1.10.1",
    "@react-native-firebase/analytics": "^14.4.0",
    "@react-native-firebase/app": "^14.4.0",
    "@react-native-firebase/crashlytics": "^14.4.0",
    "@react-native-firebase/dynamic-links": "^14.4.0",
    "@react-native-firebase/messaging": "^14.4.0",
    "@react-navigation/native": "^5.0.9",
    "@react-navigation/stack": "^5.1.1",
    "@shopify/flash-list": "^1.4.0",
    "algoliasearch": "3.32.0",
    "axios": "^0.19.1",
    "babel-plugin-transform-remove-console": "^6.9.4",
    "color": "^3.1.2",
    "dayjs": "^1.8.25",
    "eventemitter3": "^4.0.0",
    "formik": "^2.1.4",
    "imagekit-javascript": "^1.4.0",
    "jwt-decode": "^3.1.2",
    "lodash.isequal": "^4.5.0",
    "prop-types": "^15.7.2",
    "react": "18.2.0",
    "react-native": "0.71.11",
    "react-native-animatable": "^1.3.3",
    "react-native-check-box": "^2.1.7",
    "react-native-code-push": "^6.3.0",
    "react-native-fast-image": "^8.6.3",
    "react-native-fbsdk": "^1.1.2",
    "react-native-gesture-handler": "^1.4.1",
    "react-native-google-signin": "^2.1.1",
    "react-native-image-crop-picker": "^0.36.0",
    "react-native-image-zoom-viewer": "^2.2.27",
    "react-native-inappbrowser-reborn": "^3.7.0",
    "react-native-keyboard-aware-scroll-view": "^0.9.1",
    "react-native-linear-gradient": "^2.5.6",
    "react-native-modal": "^11.5.6",
    "react-native-otp-inputs": "^7.1.1",
    "react-native-permissions": "^3.6.0",
    "react-native-radio-buttons-group": "^1.0.7",
    "react-native-raw-bottom-sheet": "^2.0.6",
    "react-native-reanimated": "^1.3.0",
    "react-native-safe-area-context": "^0.7.3",
    "react-native-screens": "^3.12.0",
    "react-native-share": "^8.0.0",
    "react-native-size-matters": "^0.3.0",
    "react-native-splash-screen": "^3.2.0",
    "react-native-status-bar-height": "^2.5.0",
    "react-native-svg": "^11.0.1",
    "react-native-svg-transformer": "^0.14.3",
    "react-native-swiper": "^1.6.0-nightly.5",
    "react-native-tab-view": "^2.14.0",
    "react-native-toast-message": "^2.1.5",
    "react-native-video": "^5.1.1",
    "react-native-webengage": "^1.2.12",
    "react-native-webview": "^9.4.0",
    "react-redux": "^7.1.3",
    "recyclerlistview": "^3.0.0",
    "redux": "^4.0.5",
    "redux-logger": "^3.0.6",
    "redux-thunk": "^2.3.0",
    "reselect": "^4.0.0",
    "yup": "^0.28.3"
  },
  "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",
    "babel-jest": "^29.2.1",
    "eslint": "^8.19.0",
    "jest": "^29.2.1",
    "metro-react-native-babel-preset": "0.73.10",
    "prettier": "^2.4.1",
    "react-test-renderer": "18.2.0",
    "babel-loader": "^8.0.6",
    "babel-plugin-module-resolver": "^4.0.0",
    "eslint-config-airbnb": "^19.0.4",
    "eslint-plugin-import": "^2.26.0",
    "eslint-plugin-jsx-a11y": "^6.6.0",
    "eslint-plugin-react": "^7.30.1",
    "eslint-plugin-react-hooks": "^4.6.0",
    "eslint-plugin-react-native": "^4.0.0"
  },
  "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"
        kotlinVersion = "1.8.0"
        androidXBrowser = "1.4.0"
    }
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:7.3.1")
        classpath("com.facebook.react:react-native-gradle-plugin")
        classpath("com.google.gms:google-services:4.3.5")
        classpath("com.google.firebase:firebase-crashlytics-gradle:2.8.1")
    }
}

android/app/build.gradle

apply plugin: "com.android.application"
apply plugin: "com.facebook.react"

apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'

import com.android.build.OutputFile

/**
 * This is the configuration block to customize your React Native Android app.
 * By default you don't need to apply any configuration, just uncomment the lines you need.
 */
react {
    /* Folders */
    //   The root of your project, i.e. where "package.json" lives. Default is '..'
    // root = file("../")
    //   The folder where the react-native NPM package is. Default is ../node_modules/react-native
    // reactNativeDir = file("../node_modules/react-native")
    //   The folder where the react-native Codegen package is. Default is ../node_modules/react-native-codegen
    // codegenDir = file("../node_modules/react-native-codegen")
    //   The cli.js file which is the React Native CLI entrypoint. Default is ../node_modules/react-native/cli.js
    // cliFile = file("../node_modules/react-native/cli.js")

    /* Variants */
    //   The list of variants to that are debuggable. For those we're going to
    //   skip the bundling of the JS bundle and the assets. By default is just 'debug'.
    //   If you add flavors like lite, prod, etc. you'll have to list your debuggableVariants.
    // debuggableVariants = ["liteDebug", "prodDebug"]

    /* Bundling */
    //   A list containing the node command and its flags. Default is just 'node'.
    // nodeExecutableAndArgs = ["node"]
    //
    //   The command to run when bundling. By default is 'bundle'
    // bundleCommand = "ram-bundle"
    //
    //   The path to the CLI configuration file. Default is empty.
    // bundleConfig = file(../rn-cli.config.js)
    //
    //   The name of the generated asset file containing your JS bundle
    // bundleAssetName = "MyApplication.android.bundle"
    //
    //   The entry file for bundle generation. Default is 'index.android.js' or 'index.js'
    // entryFile = file("../js/MyApplication.android.js")
    //
    //   A list of extra flags to pass to the 'bundle' commands.
    //   See https://github.com/react-native-community/cli/blob/main/docs/commands.md#bundle
    // extraPackagerArgs = []

    /* Hermes Commands */
    //   The hermes compiler command to run. By default it is 'hermesc'
    // hermesCommand = "$rootDir/my-custom-hermesc/bin/hermesc"
    //
    //   The list of flags to pass to the Hermes compiler. By default is "-O", "-output-source-map"
    // hermesFlags = ["-O", "-output-source-map"]
}

/**
 * Set this to true to create four separate APKs instead of one,
 * one for each native architecture. This is useful if you don't
 * use App Bundles (https://developer.android.com/guide/app-bundle/)
 * and want to have separate APKs to upload to the Play Store.
 */
def enableSeparateBuildPerCPUArchitecture = false

/**
 * Set this to true to Run Proguard on Release builds to minify the Java bytecode.
 */
def enableProguardInReleaseBuilds = false

/**
 * The preferred build flavor of JavaScriptCore (JSC)
 *
 * For example, to use the international variant, you can use:
 * `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
 *
 * The international variant includes ICU i18n library and necessary data
 * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
 * give correct results when using with locales other than en-US. Note that
 * this variant is about 6MiB larger per architecture than default.
 */
def jscFlavor = 'org.webkit:android-jsc:+'

/**
 * Private function to get the list of Native Architectures you want to build.
 * This reads the value from reactNativeArchitectures in your gradle.properties
 * file and works together with the --active-arch-only flag of react-native run-android.
 */
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.app"
    defaultConfig {
        applicationId "com.app"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1"
        multiDexEnabled true
        vectorDrawables.useSupportLibrary = true
        resValue 'string', "CODE_PUSH_APK_BUILD_TIME", String.format("\"%d\"", System.currentTimeMillis())
    }

    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'
        }
        release {
            if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
                storeFile file(MYAPP_RELEASE_STORE_FILE)
                storePassword MYAPP_RELEASE_STORE_PASSWORD
                keyAlias MYAPP_RELEASE_KEY_ALIAS
                keyPassword MYAPP_RELEASE_KEY_PASSWORD
            }
        }
    }
    buildTypes {
        debug {
            signingConfig signingConfigs.debug
        }
        release {
            // Caution! In production, you need to generate your own keystore file.
            // see https://reactnative.dev/docs/signed-apk-android.
            signingConfig signingConfigs.release
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }
    // 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
            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 {
    // The version of react-native is set by the React Native Gradle Plugin
    implementation("com.facebook.react:react-android")

    // Add the Firebase SDK for Google Analytics
    implementation("com.google.firebase:firebase-analytics:18.0.2")

    // Add the SDK for Firebase Cloud Messaging
    implementation("com.google.firebase:firebase-messaging:22.0.0")

    // For animated GIF support
    implementation("com.facebook.fresco:fresco:2.+")
    implementation("com.facebook.fresco:animated-gif:2.+")

    implementation("androidx.appcompat:appcompat:1.0.0")

    implementation("com.webengage:android-sdk:3.+")

    implementation("com.android.installreferrer:installreferrer:1.1.1")

    implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.0.0")

    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)

apply from: "../../node_modules/react-native-code-push/android/codepush.gradle"

settings.gradle

rootProject.name = 'App'
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
include ':react-native-code-push'
project(':react-native-code-push').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-code-push/android/app')
include ':react-native-video'
project(':react-native-video').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-video/android-exoplayer')
include ':app'
includeBuild('../node_modules/react-native-gradle-plugin')

Screenshot

image

cortinico commented 1 year ago

Have you yarn install afterwards? Can you run ls -la node_modules/react-native-gradle-plugin and return the output?

nikit-psl commented 1 year ago

Yes, I deleted node_modules folder and ran yarn install command after upgrading everything else.

Output of ls -la node_modules/react-native-gradle-plugin -

total 56
drwxr-xr-x   12 admin  staff    384 Jun 19 12:11 .
drwxr-xr-x  803 admin  staff  25696 Jun 19 12:10 ..
drwxr-xr-x    3 admin  staff     96 Jun 19 12:11 .gradle
-rw-r--r--    1 admin  staff    488 Aug  3  2022 README.md
-rw-r--r--    1 admin  staff    868 Aug  3  2022 build.gradle.kts
drwxr-xr-x    3 admin  staff     96 Jun 19 12:09 gradle
-rwxr-xr-x    1 admin  staff   5774 Aug  3  2022 gradlew
-rw-r--r--    1 admin  staff   2763 Aug  3  2022 gradlew.bat
drwxr-xr-x    4 admin  staff    128 Jun 19 12:09 node_modules
-rw-r--r--    1 admin  staff    744 Aug  3  2022 package.json
-rw-r--r--    1 admin  staff    281 Aug  3  2022 settings.gradle.kts
drwxr-xr-x    3 admin  staff     96 Jun 19 12:09 src
cortinico commented 1 year ago

can you share the output of your android/gradle/wrapper/gradle-wrapper.properties file?

nikit-psl commented 1 year ago
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
github-actions[bot] commented 1 year ago
:warning: Missing Reproducible Example
:information_source: It looks like your issue is missing a reproducible example. Please provide either:
cortinico commented 1 year ago

Thanks for sharing. Unfortunately I can't help you further without a reproducer.

nikit-psl commented 1 year ago

@cortinico not sure why this worked, but when I manually installed react-native-gradle-plugin, the issue got fixed. I know that it's not recommended as mentioned here, but this is the only thing that worked for me as of now. Any ideas what might be happening?

cortinico commented 1 year ago

Any ideas what might be happening?

Sadly not. Can you try to remove the manual installation of react-native-gradle-plugin and then try to yarn why react-native-gradle-plugin and share the output? I'm wondering if there is something goign on with package dependencies.

Devmaleeq commented 1 year ago

I'm also experiencing this exact issue. What I simple did was to comment out. I also discovered that this might be happening to those of us who aren't using fresh installation.

The react native upgrade helper shows that we need to reference react-native-gradle-plugin at some point. https://react-native-community.github.io/upgrade-helper/?from=0.66.5&to=0.68.0#RnDiffApp-android-settings.gradle

toscalivia83 commented 1 year ago

I'm having the same problem with RN 0.71.10

cortinico commented 1 year ago

What I simple did was to comment out.

Comment out what @Devmaleeq ?

prft-michael-feuvrel commented 1 year ago

I had this same issue which I'm pretty sure was due to incorrect java version (8). It resolved after switching java version to 11. https://reactnative.dev/docs/next/environment-setup?platform=android#jdk

drmas commented 1 year ago

Make sure you you follow the upgrade steps in your android/build.gradle

https://react-native-community.github.io/upgrade-helper/?from=0.70.11&to=0.71.12#RnDiffApp-android-build.gradle

williamsilveira45 commented 1 year ago

I'm facing the same issue, no news? =( this is really sad

cortinico commented 1 year ago

Closing as @nikit-psl is unresponsive.

This issue is most likely caused from a wrong settings.gradle file in your project.

Specifically, if you're on React Native 0.72+, that file should look as follows: https://github.com/facebook/react-native/blob/79c4ec1a9a27dc0fd76c1a65ebcb77257d3d4095/packages/react-native/template/android/settings.gradle#L2-L4

If you're on React Native <= 0.71, it should look as follows: https://github.com/facebook/react-native/blob/7636e4c10209ab26b0d9f79ca34d08e874635dd1/template/android/settings.gradle#L2-L4

sunnylqm commented 1 year ago

this error may be caused by incorrect jdk version in android studio

folusara commented 1 year ago

i had to reinstall react-native-gradle-plugin

Pattygeek commented 12 months ago

Closing as @nikit-psl is unresponsive.

This issue is most likely caused from a wrong settings.gradle file in your project.

Specifically, if you're on React Native 0.72+, that file should look as follows:

https://github.com/facebook/react-native/blob/79c4ec1a9a27dc0fd76c1a65ebcb77257d3d4095/packages/react-native/template/android/settings.gradle#L2-L4

If you're on React Native <= 0.71, it should look as follows:

https://github.com/facebook/react-native/blob/7636e4c10209ab26b0d9f79ca34d08e874635dd1/template/android/settings.gradle#L2-L4

this worked for me.

KarthiKeyan05046 commented 12 months ago

@cortinico Thankyou

dimisus commented 11 months ago

Closing as @nikit-psl is unresponsive.

This issue is most likely caused from a wrong settings.gradle file in your project.

Specifically, if you're on React Native 0.72+, that file should look as follows:

https://github.com/facebook/react-native/blob/79c4ec1a9a27dc0fd76c1a65ebcb77257d3d4095/packages/react-native/template/android/settings.gradle#L2-L4

If you're on React Native <= 0.71, it should look as follows:

https://github.com/facebook/react-native/blob/7636e4c10209ab26b0d9f79ca34d08e874635dd1/template/android/settings.gradle#L2-L4

This does NOT work when you have set the combination:

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

build.gradle: classpath("com.facebook.react:react-native-gradle-plugin")

app/build.gradle: apply plugin: "com.facebook.react"

daskabe commented 11 months ago

I had same configuration as @dimisus above and got it resolved by doing npm i react-native-gradle-plugin - which installed "react-native-gradle-plugin": "^0.71.19" .

The plugin is already configured for new projects created using npx react-native init. You don't need to do any extra steps to install it if you created your app with this command. https://reactnative.dev/docs/react-native-gradle-plugin

My guess is when you run the build somewhere other than where you did react-native init ; like on git CI VM ; the package doesnt exist anywhere.

error before doing npm i react-native-gradle-plugin in the project.

Run cd android && ./gradlew assembleDebug --no-daemon
Downloading https://services.gradle.org/distributions/gradle-[8](https://github.com/daskabe/abc-reactNative-typescript-mobile/actions/runs/7110134331/job/19356153804#step:11:9).0.1-all.zip
...............10%................20%................30%................40%................50%................60%................70%................80%................[9](https://github.com/daskabe/abc-reactNative-typescript-mobile/actions/runs/7110134331/job/19356153804#step:11:10)0%................[10](https://github.com/daskabe/abc-reactNative-typescript-mobile/actions/runs/7110134331/job/19356153804#step:11:11)0%

Welcome to Gradle 8.0.1!

Here are the highlights of this release:
 - Improvements to the Kotlin DSL
 - Fine-grained parallelism from the first build with configuration cache
 - Configurable Gradle user home cache cleanup

For more details see https://docs.gradle.org/8.0.1/release-notes.html

To honour the JVM settings for this build a single-use Daemon process will be forked. See https://docs.gradle.org/8.0.1/userguide/gradle_daemon.html#sec:disabling_the_daemon.
Daemon will be stopped at the end of the build 

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'abc_rn_ts_mobile'.
> Could not determine the dependencies of null.
   > Could not resolve all task dependencies for configuration ':classpath'.
      > Could not resolve com.facebook.react:react-native-gradle-plugin.
        Required by:
            project :
         > Module version 'com.facebook.react:react-native-gradle-plugin' is not unique in composite: can be provided by [project :gradle-plugin, project :react-native-gradle-plugin].

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1m [25](https://github.com/daskabe/abc-reactNative-typescript-mobile/actions/runs/7110134331/job/19356153804#step:11:26)s

settings.gradle

rootProject.name = 'abc_rn_ts_mobile'
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')

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")
    }
}

allprojects {
  repositories {
    google()
    jcenter()
  }
}
allenmackley commented 11 months ago

In my settings.gradle, I had to change includeBuild('../node_modules/@react-native/gradle-plugin') to includeBuild('../node_modules/react-native-gradle-plugin')

in order match the classpath in the build.gradle of classpath("com.facebook.react:react-native-gradle-plugin")

However, I noticed that the @react-native/gradle-plugin package has the latest updates on NPM and that react-native-gradle-plugin is likely deprecated or will be soon. The only issue with using the @react-native/gradle-plugin version is that I don't know how to add the correct syntax in the classpath.

I tried this, for example, which doesn't work: classpath("com.facebook.react:@react-native/gradle-plugin")

Does anybody know how to write that syntax correctly so it lines up with the new package name?

spinoza1791 commented 8 months ago

This works for me. Thx all!

RN 73.5, gradle 8.4, android gradle 8.3.0

package.json "@react-native/gradle-plugin": "^0.73.4",

android/build.gradle buildscript { ext { kotlin_version = '1.9.22' buildToolsVersion = "34.0.0" minSdkVersion = 30 compileSdkVersion = 34 targetSdkVersion = 34

}

dependencies {
    classpath("com.android.tools.build:gradle:8.3.0")
    classpath("com.facebook.react:react-native-gradle-plugin")
    classpath "de.undercouch:gradle-download-task:5.4.0"
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}

settings.gradle 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')

enlightenedpie commented 8 months ago

Have you yarn install afterwards? Can you run ls -la node_modules/react-native-gradle-plugin and return the output?

I ran across this same issue/error today and I found this github issue from google... I followed @cortinico suggestion to output the react-native-gradle-plugin folder and this is what I saw:

total 8
drwxr-xr-x    4 davidpaul  staff    128 Mar  9 09:19 .
drwxr-xr-x@ 675 davidpaul  staff  21600 Mar  9 09:19 ..
-rw-r--r--    1 davidpaul  staff    933 Mar  9 09:19 .project
drwxr-xr-x    3 davidpaul  staff     96 Mar  9 09:19 bin

This was after multiple rm -rf node_modules && npm i... For some reason that package wasn't fully downloading, so I manually added it via npm i react-native-gradle-plugin, et voila!

total 56
drwxr-xr-x@  11 davidpaul  staff    352 Mar  9 09:28 .
drwxr-xr-x@ 675 davidpaul  staff  21600 Mar  9 09:28 ..
-rw-r--r--@   1 davidpaul  staff    488 Mar  9 09:28 README.md
drwxr-xr-x   10 davidpaul  staff    320 Mar  9 09:28 bin
-rw-r--r--@   1 davidpaul  staff   1657 Mar  9 09:28 build.gradle.kts
drwxr-xr-x@   3 davidpaul  staff     96 Mar  9 09:28 gradle
-rwxr-xr-x@   1 davidpaul  staff   8070 Mar  9 09:28 gradlew
-rw-r--r--@   1 davidpaul  staff   2763 Mar  9 09:28 gradlew.bat
-rw-r--r--@   1 davidpaul  staff    711 Mar  9 09:28 package.json
-rw-r--r--@   1 davidpaul  staff    339 Mar  9 09:28 settings.gradle.kts
drwxr-xr-x@   3 davidpaul  staff     96 Mar  9 09:28 src

For some reason the entire package was not being pulled from NPM, so I had to manually do it. Everything works now.

RN 0.70.6

cortinico commented 8 months ago

so I manually added it via npm i react-native-gradle-plugin, et voila!

Doing npm i react-native-gradle-plugin is not correct and will break your project the next time you update react native

emuter commented 8 months ago

running npm i -g fixes it

sultandelux commented 7 months ago

IN MY CASE I RESTARTED WATCHMAN

shrynshjn commented 6 months ago

In my case the issue was because of react-native-screens. Result of yarn why react-native-gradle-plugin

=> Found "react-native-gradle-plugin@0.0.3"
info Reasons this module exists
   - "react-native-screens" depends on it
   - Hoisted from "react-native-screens#react-native-gradle-plugin"
info Disk size without dependencies: "472KB"
info Disk size with unique dependencies: "2.18MB"
info Disk size with transitive dependencies: "27.36MB"
info Number of shared dependencies: 85
=> Found "react-native#react-native-gradle-plugin@0.70.3"
info This module exists because "react-native" depends on it.
info Disk size without dependencies: "260KB"
info Disk size with unique dependencies: "260KB"
info Disk size with transitive dependencies: "260KB"
info Number of shared dependencies: 0

i wasn't using it so simply uninstall the library fixed the problem for me

LIND96 commented 1 month ago

make sure node_modules/@react-native/gradle-plugin is exist, in my case this file is not exist and re install package use npm install