0

After creating a new monorepo with a package for a new react-native project (0.77.2), the Android build was failing with the following error:

FAILURE: Build failed with an exception.

* Where:
Settings file '<project_name>/packages/<package_name>/android/settings.gradle' line: 2

* What went wrong:
Error resolving plugin [id: 'com.facebook.react.settings']
> Included build '<project_name>/packages/<package_name>/node_modules/@react-native/gradle-plugin' does not exist.

* 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 462ms
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 '<project_name>/packages/<package_name>/android/settings.gradle' line: 2 * What went wrong:
Error resolving plugin [id: 'com.facebook.react.settings']
> Included build '<project_name>/packages/<package_name>/node_modules/@react-native/gradle-plugin' does not exist. * 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 462ms.
info Run CLI with --verbose flag for more details.
node:internal/errors:984
  const err = new Error(message);
              ^

Error: Command failed: yarn workspace <package_name> android

1 Answer 1

0

After a few tries I found this blog post, the configuration it suggests did not work on my project, however it had insights about the location of node_modules (it is a couple of folders above what it "should be", i.e. an extra ../../) .
After some modifications I got it working:

packages/<package_name>/android/settings.gradle - add extra ../../:

pluginManagement { includeBuild("../../../node_modules/@react-native/gradle-plugin") }
...
includeBuild('../../../node_modules/@react-native/gradle-plugin')

packages/<package_name>/android/app/build.gradle - modify the default locations and add extra ../../:

...
reactNativeDir = file("../../../../node_modules/react-native")
...
codegenDir = file("../../../../node_modules/@react-native/codegen")
...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.