facebook / react-native

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

[android] Plugin [id: 'com.facebook.react.settings'] was not found in any of the following sources #46046

Closed HamoBoker closed 2 months ago

HamoBoker commented 3 months ago

Description

build fail on android after upgrading from 0.74.5 to 0.75.1 caused by "/android/settings.gradle' line: 2"

pluginManagement { includeBuild("../../../node_modules/@react-native/gradle-plugin") }
plugins { id("com.facebook.react.settings") }
extensions.configure(com.facebook.react.ReactSettingsExtension){ ex -> ex.autolinkLibrariesFromCommand() }
rootProject.name = 'driver'
include ':app'
includeBuild('../../../node_modules/@react-native/gradle-plugin')

i'm using monorepo, i rechecked node_modules path and it is correct

Steps to reproduce

  1. upgrade to react-native@0.75.1
  2. react-native run-android

React Native Version

0.75.1

Affected Platforms

Runtime - Android

Output of npx react-native info

...

Stacktrace or Logs

FAILURE: Build failed with an exception.

* Where:
Settings file '/Users/hamoboker/Projects/shoory/shoory-mobile/apps/driver/android/settings.gradle' line: 2

* What went wrong:
Plugin [id: 'com.facebook.react.settings'] was not found in any of the following sources:

- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Included Builds (No included builds contain this plugin)
- Plugin Repositories (plugin dependency must include a version number for this source)

Reproducer

...

Screenshots and Videos

No response

react-native-bot commented 3 months ago
:warning: Missing Reproducible Example
:information_source: We could not detect a reproducible example in your issue report. Please provide either:
  • If your bug is UI related: a Snack
  • If your bug is build/update related: use our Reproducer Template. A reproducer needs to be in a GitHub repository under your username.
react-native-bot commented 3 months ago
:warning: Missing Reproducible Example
:information_source: We could not detect a reproducible example in your issue report. Please provide either:
jieey1140 commented 3 months ago

same issue

lovegaoshi commented 3 months ago

check your @react-native/gradle-plugin resolution in yarn.lock/package-lock.json; if you have any lingering other than 0.75.1 (eg i have 0.74.1 left in there) you have to remove node_modules and regenerate your lock file

cortinico commented 3 months ago

@lovegaoshi is right. Can you confirm you have @react-native/gradle-plugin version 0.75.1 installed?

HamoBoker commented 3 months ago

@lovegaoshi is right. Can you confirm you have @react-native/gradle-plugin version 0.75.1 installed?

I'll recheck and give you feedback

HamoBoker commented 3 months ago

Thank you @lovegaoshi & @cortinico issue has been solved

HamoBoker commented 2 months ago

@cortinico The problem occurred again after reinstalling node_modules.

I created a new project using npx @react-native-community/cli init and faced the same issue. I tried removing ~/.gradle/caches and building again but that didn't solve the problem

Logs from the newly created app

~/Projects/SomeApp git:[main]
yarn android
info A dev server is already running for this project on port 8081.
info Installing the app...

info 💡 Tip: Make sure that you have set up your development environment correctly, by running npx react-native doctor. To read more about doctor command visit: https://github.com/react-native-community/cli/blob/main/packages/cli-doctor/README.md#doctor 

FAILURE: Build failed with an exception.

* Where:
Settings file '/Users/hamoboker/Projects/SomeApp/android/settings.gradle' line: 2

* What went wrong:
Error resolving plugin [id: 'com.facebook.react.settings']
> Could not read workspace metadata from /Users/hamoboker/.gradle/caches/8.8/kotlin-dsl/accessors/b22002a57a45d84a557a6d199ea7ef01/metadata.bin

* 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 596ms
error Failed to install the app. Command failed with exit code 1: ./gradlew app:installDebug -PreactNativeDevServerPort=8081 FAILURE: Build failed with an exception. * Where:
Settings file '/Users/hamoboker/Projects/SomeApp/android/settings.gradle' line: 2 * What went wrong:
Error resolving plugin [id: 'com.facebook.react.settings']
> Could not read workspace metadata from /Users/hamoboker/.gradle/caches/8.8/kotlin-dsl/accessors/b22002a57a45d84a557a6d199ea7ef01/metadata.bin * 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 596ms.
info Run CLI with --verbose flag for more details.
cortinico commented 2 months ago

Seems related to: https://github.com/gradle/gradle/issues/28974

I don't have a solution at the moment and I also cannot reproduce:

https://github.com/user-attachments/assets/62058329-2649-4e1a-9c6b-e109a4fd70f7

I would have suggested to attempt removing the .gralde/caches folder which you already did. I'd like to see if other users are also having this problem or not

Akanzi76 commented 2 months ago

/settings.gradle/ rootProject.name = 'your_project_name' 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')

Akanzi76 commented 2 months ago

/Android/app/build.gradle apply plugin: "com.android.application" apply plugin: "org.jetbrains.kotlin.android" apply plugin: "com.facebook.react"

/**

/**

/**

android { ndkVersion rootProject.ext.ndkVersion buildToolsVersion rootProject.ext.buildToolsVersion compileSdk rootProject.ext.compileSdkVersion

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

signingConfigs { release { storeFile file("your-release-key.keystore") storePassword "1111111" // Key store key enter keyAlias "your-key-alias" keyPassword "1111111" // Key store key enter } }

buildTypes { release { signingConfig signingConfigs.release minifyEnabled enableProguardInReleaseBuilds proguardFiles getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro" } }

}

dependencies { // The version of react-native is set by the React Native Gradle Plugin implementation("com.facebook.react:react-android")

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)

sarwanand24 commented 2 months ago

I tried everything listed above but nothing is working.

jieey1140 commented 2 months ago

@sarwanand24

I'm not sure if this will help, but you can also try this

pluginManagement { includeBuild(“../../../node_modules/@react-native/gradle-plugin”) }
plugins { id(“com.facebook.react.settings”) }
extensions.configure(com.facebook.react.ReactSettingsExtension){ ex -> ex.autolinkLibrariesFromCommand() } 

Change it like below

pluginManagement {
  includeBuild(new File([“node”, “--print”, “require.resolve(‘@react-native/gradle-plugin/package.json’)”].execute(null, rootDir).text.trim()).getParentFile().toString())
}
plugins { id(“com.facebook.react.settings”) }
extensions.configure(com.facebook.react.ReactSettingsExtension){ ex -> ex.autolinkLibrariesFromCommand() }

Test environment macos 14.4.1 (M1 Pro) Using pnpm workspace (monorepo) bare react-native 0.75.1 node 20.16.0

This got me past the above error, but I got an error on the expo-images side, so I downgraded to bare React Native temporarily. If you don't use the above packages, it should work :(

sarwanand24 commented 2 months ago

@jieey1140 I deleted the gradle many times and rebuild the project then it worked for me.

raahimkhan commented 2 months ago

@lovegaoshi is right. Can you confirm you have @react-native/gradle-plugin version 0.75.1 installed?

This worked for me too!

devic021 commented 2 months ago

I have same issue, no metter what i do, i'm getting same error. Removed /node_modules, .gradle. Tried everything, but the error in Andorid remains.

lovegaoshi commented 2 months ago

did yall regenerate yarn.lock though

On Sun, Aug 18, 2024, 9:04 AM Djordje Devic @.***> wrote:

I have same issue, no metter what i do, i'm getting same error. Removed /node_modules, .gradle. Tried everything, but the error in Andorid remains.

— Reply to this email directly, view it on GitHub https://github.com/facebook/react-native/issues/46046#issuecomment-2295311265, or unsubscribe https://github.com/notifications/unsubscribe-auth/AZMOVVUQ7SRSAXQQHAYPQBDZSDAXVAVCNFSM6AAAAABMSK64ACVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOJVGMYTCMRWGU . You are receiving this because you were mentioned.Message ID: @.***>

devic021 commented 2 months ago

Yes i did, everything from scratch installed with yarn

kyungjoongo77777 commented 2 months ago

yarn add @react-native/gradle-plugin@0.75.1 --exact

HamoBoker commented 2 months ago

Currently my issue is related to gradle cache

Could not read workspace metadata from /Users/hamoboker/.gradle/caches/[GRADLE_VERSION]

getting this error on GRADLE_VERSION = 8.8 and 8.6

[UPDATE]

@cortinico i solved my issue by removing rm -rf ~/.gradle/caches and restarting the device removing ~/.gradle/caches without restarting didn't solve the problem.

@devic021 can you try this and share feedback ? if issue still occur make sure you have @react-native/gradle-plugin installed

Projects tested on react-native@0.74.5 - gradle 8.6 react-native@0.75.1 - gradle 8.8

cortinico commented 2 months ago

@HamoBoker thanks for the update, I'm closing then:

@cortinico i solved my issue by removing rm -rf ~/.gradle/caches and restarting the device removing ~/.gradle/caches without restarting didn't solve the problem so i guess restart is required after removing folder.

Generally doing:

cd android && ./gradlew --stop && rm -rf ~/.gradle/caches

should be sufficient rather than having to reboot.

Please open separate issues if you're having similar problmes.

dark-doraemon commented 2 months ago

Does anyone have this error ? image

RahulLodhi-Git commented 2 months ago

@HamoBoker thanks for the update, I'm closing then:

@cortinico i solved my issue by removing rm -rf ~/.gradle/caches and restarting the device removing ~/.gradle/caches without restarting didn't solve the problem so i guess restart is required after removing folder.

Generally doing:

cd android && ./gradlew --stop && rm -rf ~/.gradle/caches

should be sufficient rather than having to reboot.

@cortinico @HamoBoker Thanks, your solution works for me.

cd android && ./gradlew --stop && rm -rf ~/.gradle/caches

V-SATHISH2109 commented 2 months ago

FAILURE: Build failed with an exception.

still showing same error "node_modules/@react-native/gradle-plugin": { "version": "0.75.1", "resolved": "https://registry.npmjs.org/@react-native/gradle-plugin/-/gradle-plugin-0.75.1.tgz", "integrity": "sha512-a2gVjX3MB9TF9QZSKje79n1GDAnseTU94VIcFH/4DS3KjbK3yrNXsu1maxGZxDUAKmTUH7Rz4An/Rb5nkZG7dw==", "dev": true, "engines": { "node": ">=18" } },

RahulLodhi-Git commented 2 months ago

FAILURE: Build failed with an exception.

  • Where: Settings file 'D:\delet\reactnative\android\settings.gradle' line: 2

  • What went wrong: Error resolving plugin [id: 'com.facebook.react.settings']

still showing same error "node_modules/@react-native/gradle-plugin": { "version": "0.75.1", "resolved": "https://registry.npmjs.org/@react-native/gradle-plugin/-/gradle-plugin-0.75.1.tgz", "integrity": "sha512-a2gVjX3MB9TF9QZSKje79n1GDAnseTU94VIcFH/4DS3KjbK3yrNXsu1maxGZxDUAKmTUH7Rz4An/Rb5nkZG7dw==", "dev": true, "engines": { "node": ">=18" } },

Hi @V-SATHISH2109, Last couple days ago, I was facing the same errors.

Below things work for me

  1. Recheck the installed JAVA SDK version, react-native 0.75 requires a min JAVA sdk version 17. JAVA -- version
  1. Clean the gradle caches via below command. cd android && ./gradlew --stop && rm -rf ~/.gradle/caches
V-SATHISH2109 commented 2 months ago

I have one small doubt i want to use this command in project Android folders

On Sat, Aug 24, 2024, 9:37 AM Rahul Lodhi @.***> wrote:

FAILURE: Build failed with an exception.

-

Where: Settings file 'D:\delet\reactnative\android\settings.gradle' line: 2

What went wrong: Error resolving plugin [id: 'com.facebook.react.settings']

still showing same error @./gradle-plugin": { "version": "0.75.1", "resolved": " @./gradle-plugin/-/gradle-plugin-0.75.1.tgz ", "integrity": "sha512-a2gVjX3MB9TF9QZSKje79n1GDAnseTU94VIcFH/4DS3KjbK3yrNXsu1maxGZxDUAKmTUH7Rz4An/Rb5nkZG7dw==", "dev": true, "engines": { "node": ">=18" } },

Hi @V-SATHISH2109 https://github.com/V-SATHISH2109, Last couple days ago, I was facing the same errors.

Below things work for me

1.

Recheck the installed JAVA SDK version, react-native 0.75 requires a min JAVA sdk version 17. JAVA -- version 2.

Clean the gradle cache via below command inside the Android.

cd android && ./gradlew --stop && rm -rf ~/.gradle/caches

— Reply to this email directly, view it on GitHub https://github.com/facebook/react-native/issues/46046#issuecomment-2308043658, or unsubscribe https://github.com/notifications/unsubscribe-auth/A24F6GDP3CXDHAQKWOYNN73ZTABJ5AVCNFSM6AAAAABMSK64ACVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMBYGA2DGNRVHA . You are receiving this because you were mentioned.Message ID: @.***>

RahulLodhi-Git commented 2 months ago

I have one small doubt i want to use this command in project Android folders

On Sat, Aug 24, 2024, 9:37 AM Rahul Lodhi @.***> wrote:

FAILURE: Build failed with an exception.

-

Where: Settings file 'D:\delet\reactnative\android\settings.gradle' line: 2

What went wrong: Error resolving plugin [id: 'com.facebook.react.settings']

still showing same error @./gradle-plugin": { "version": "0.75.1", "resolved": " @./gradle-plugin/-/gradle-plugin-0.75.1.tgz ", "integrity": "sha512-a2gVjX3MB9TF9QZSKje79n1GDAnseTU94VIcFH/4DS3KjbK3yrNXsu1maxGZxDUAKmTUH7Rz4An/Rb5nkZG7dw==", "dev": true, "engines": { "node": ">=18" } },

Hi @V-SATHISH2109 https://github.com/V-SATHISH2109, Last couple days ago, I was facing the same errors.

Below things work for me

1.

Recheck the installed JAVA SDK version, react-native 0.75 requires a min JAVA sdk version 17. JAVA -- version 2.

Clean the gradle cache via below command inside the Android.

cd android && ./gradlew --stop && rm -rf ~/.gradle/caches

— Reply to this email directly, view it on GitHub https://github.com/facebook/react-native/issues/46046#issuecomment-2308043658, or unsubscribe https://github.com/notifications/unsubscribe-auth/A24F6GDP3CXDHAQKWOYNN73ZTABJ5AVCNFSM6AAAAABMSK64ACVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMBYGA2DGNRVHA . You are receiving this because you were mentioned.Message ID: @.***>

No, you can run from projects's root folder, because this command already includes the change directory command for changing the folder.

danielniquet commented 2 months ago

@react-native/gradle-plugin

Adding it as a devDependency solved it for me

raahimkhan commented 2 months ago

yarn add @react-native/gradle-plugin@0.75.1 --exact

This gives the following error

FouadMagdy01 commented 2 months ago

I was facing this problem when i upgraded an old project to the latest RN version 0.75.2

and i managed to solve it in android studio, open file > Project Structure > Project and i have set gradle version to 8.2.0

manzoorsofi commented 2 months ago

Just started the project with the latest version of React Native at first build only got this error

i tried removing gradle caches etc Nope!

kacper-ragankiewicz commented 2 months ago

same issue

ClenildoCardoso commented 1 month ago

Claro! Aqui está a tradução do seu passo a passo:


Simple solution:

  1. Restart your PC
  2. Navigate to your project
  3. Delete the .gradle folder
  4. Run cd android
  5. Run gradlew clean
  6. Run yarn android

Thank me later!!

tonsnoei commented 1 month ago

The real solution!!

After deeply investigated this issue, this is my verdict to fix the issue for React Native version 0.74.5.

Is has everything to do with a dangling react-native/gradle-plugin in the yarn.lock file.

If you have the react-native-windows dependency in your package.json ensure it has the same version as the react-native dependency. Fix this first before performing the next steps. If this does not fix it after performing the steps below, it has something to do with another outdated dependency in the packages.json

Perform the next steps from the root of your project.

  1. Empty your yarn.lock file. (Deleting the file will make yarn unhappy)
  2. Delete node_modules
  3. Run: yarn install
  4. Run: cd android
  5. Run: gradlew clean
  6. Run: yarn android

This will fix it. Happy coding! 😄

wunai-max commented 1 month ago

74FA52E5-4D74-4022-8ED1-7692AE4CB71A E98DE4E6-E79E-4502-9BBD-F4A46FA45591 Does anyone know what's going on here have any idea what to do about it? react-native 0.71.3 Sync Project with Gradle Files Resulting error

mafzal11 commented 3 weeks ago

Claro! Aqui está a tradução do seu passo a passo:

Simple solution:

  1. Restart your PC
  2. Navigate to your project
  3. Delete the .gradle folder
  4. Run cd android
  5. Run gradlew clean
  6. Run yarn android

Thank me later!!

I had the same issue unitl I followed these step. Thank you so much issue resolved.

vladiiic commented 2 weeks ago

If you are using windows, it has a limit on file path length, which may cause issues.

You can enable long path support: Press Win + R, type gpedit.msc and OK

Now: Computer Configuration > Administrative Templates > System > Filesystem > Enable Win32 long paths

Last: Double-click Enable Win32 long paths and set it to Enabled.

(P.S. for me problem was that gradle cached some files in super long folder name on windows)

hkn-tr commented 2 weeks ago

for \android\settings.gradle' line: 2 * What went wrong: Error resolving plugin [id: 'com.facebook.react.settings'] error

just run npm install @react-native/gradle-plugin@0.75.1 --exact or if yarn yarn add @react-native/gradle-plugin@0.75.1 --exact

TomAtterton commented 2 weeks ago

I just ran into this issue when using expo@next and upgrading to new arch then downgrading.

My solution was was ./gradlew --stop && rm -rf ./gradle/caches && ./gradlew clean

Worth noting I also cleared node_module and deleted and prebuilt the android project to no prevail.

Divyanshukla commented 1 week ago

Getting same error

hhimanshii108 commented 3 days ago

FAILURE: Build failed with an exception.

"dependencies": { "@react-native/gradle-plugin": "^0.75.1", "react": "18.3.1", "react-native": "0.76.1" },