react-native\react.gradle'不存在

ora*_*nge 18 react-native

我使用react native创建了一个应用程序,我正在尝试生成apk.在http://facebook.github.io/react-native/docs/signed-apk-android.html#content的文档中完成后.发生错误,它表示无法读取脚本react-native\react.gradle',因为它不存在.

这是错误

FAILURE: Build failed with an exception.

* Where:
Build file 'C:\Users\User\Desktop\Aaa\android\app\build.gradle' line: 68

* What went wrong:
A problem occurred evaluating project ':app'.
> Could not read script 'C



*   // override which node gets called and with what additional arguments
*   nodeExecutableAndArgs: ["node"],
*
*   // supply additional arguments to the packager
*   extraPackagerArgs: []
* ]
*/

apply from: "../../node_modules/react-native/react.gradle"

/**
 * Set this to true to create two separate APKs instead of one:
 *   - An APK that only works on ARM devices
 *   - An APK that only works on x86 devices
 * The advantage is the size of the APK is reduced by about 4MB.
 * Upload all the APKs to the Play Store and people will download
 * the correct one based on the CPU architecture of their device.
 */
def enableSeparateBuildPerCPUArchitecture = false
Run Code Online (Sandbox Code Playgroud)

小智 34

为了避免将来的混乱,react.gradle 在 0.72 中被删除https://github.com/facebook/react-native/blob/main/CHANGELOG.md#v0720。如果您使用的是该版本,则可能需要更新您的 app/build.gradle 文件而不是接受的答案

  • @Irfanwani,@YM,就我而言,我必须在我的`android/app/build.gradle`中注释掉`apply from: "../../node_modules/react-native/react.gradle"` (14认同)
  • 以及如何更新 app/build.gradle (4认同)

Ada*_*Kis 25

转到项目的根文件夹并运行npm install,它将生成必要的文件,包括react.gradle

如果您没有node.js,可以从这里下载:https://nodejs.org/en/download/

  • 如果您在 2023 年或之后遇到问题,特别是更新较旧的应用程序时,请参阅此答案,而不是关于在 0.72 中删除react.gradle /sf/answers/5366963101/ (3认同)

cbd*_*dev 12

如果您在2023 年settings.gradle更换时遇到此问题includeBuild('../node_modules/@react-native/gradle-plugin')

  • 0.71 和 0.72 之间的版本:

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

  • 版本 > 0.72 :

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


小智 5

你可以做 npm安装

并且所有问题都结束了。

  • 这个答案太宽泛了……它无法解决为什么react.gradle无法读取的问题。 (2认同)