簡體   English   中英

反應原生 gradle 構建失敗

[英]React native gradle build failed

我從 github 克隆了一個react-native項目,下面是我為了使它在我的本地 ubuntu 20.04 機器上工作而遵循的步驟:

(項目之前是expo管理的,現在因為有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 ://www.codegrepper.com/code-examples/whatever/BUG!+exception+in+phase+'semantic+analysis'+in+source+unit+'_BuildScript_'+Unsupported+ https://www.codegrepper.com/code-examples/whatever/BUG!+exception+in+phase+'semantic+analysis'+in+source+unit+'_BuildScript_'+Unsupported+class+file+major+version+61

第三個遇到的錯誤:-

再次運行npx react-native run-android並且這次遇到了這 2 個構建錯誤:

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

第四個遇到的錯誤:-

> 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。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM