React原生gradle构建失败



我从github上克隆了一个react-native项目,下面是我为了使它在我本地的ubuntu 20.04机器上工作所遵循的步骤:

(项目是世博管理较早,但现在它被弹出,因为有androidios文件夹)

  1. 创建了我的本地特征分支->git checkout -b feature
  2. 安装了package中的所有包。json→yarn install
  3. 运行npx react-native run-android在android模拟器上运行应用

第一次遇到错误: -

Could not write standard input to Gradle build daemon.
java.io.IOException: Stream closed
* What went wrong:
Unable to start the daemon process.
This problem might be caused by incorrect configuration of the daemon.
For example, an unrecognized jvm option is used.
Please read the following process output to find out more:
-----------------------
Unrecognized VM option 'MaxPermSize=512m'
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

为了解决这个问题,我使用了这个https://stackoverflow.com/a/69630720/11685381答案并从我的gradle.properties中删除了-XX:MaxPermSize=512m

第二次遇到错误: -

再次使用npx react-native run-android并遇到另一个构建错误:-

* What went wrong:
Could not open settings generic class cache for settings file '/home/user/project/android/settings.gradle' (/home/user/.gradle/caches/6.9/scripts/5bii70nilhgbvb8zyo7v963b7).
> BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 61
为了解决这个问题,我使用了这个解决方案:https://www.codegrepper.com/code-examples/whatever/BUG!+exception+in+phase+'semantic+analysis'+in+source+unit+'_BuildScript_'+Unsupported+class+file+major+version+61

第3次遇到错误: -

再次运行npx react-native run-android,这次遇到以下两个构建错误:

1: Task failed with an exception.
-----------
* Where:
Build file '/home/user/project/node_modules/expo-gl-cpp/android/build.gradle' line: 307
* What went wrong:
Default side-by-side NDK installation is not found.
Set $ANDROID_NDK_HOME environment variable correctly or setup ndk.dir in local.properties.
> NDK is not installed
2: Task failed with an exception.
-----------
* What went wrong:
A problem occurred configuring project ':expo'.
> compileSdkVersion is not specified. Please add it to build.gradle

为了解决第一个问题,即NDK is not installed(它已安装),我在project/android目录下创建了local.properties,并粘贴了以下路径:

sdk.dir=/home/user/Android/Sdk
ndk.dir=/home/user/Android/Sdk/ndk/24.0.8215888

第4次遇到错误: -

> Task :app:generatePackageList FAILED
Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
* Where:
Script '/home/user/project/node_modules/@react-native-community/cli-platform-android/native_modules.gradle' line: 131
* What went wrong:
Execution failed for task ':app:generatePackageList'.
> argument type mismatch

为了解决这个问题,我尝试了这个解决方案:https://stackoverflow.com/a/68180959/11685381但这再次下载了我之前也有过的gradle 6.9,并再次到第二次遇到错误

我已经这样做了2天,有人可以帮助我在这里我做错了什么?

尝试从

更新build.grade
classpath("com.android.tools.build:gradle:3.5.3")

classpath("com.android.tools.build:gradle:3.5.4")

这只是一个例子。尝试更新Gradle.

最新更新