A problem occurred starting process ‘command ‘bash‘‘

Android React Native 异常处理

异常信息

bash 复制代码
> Task :react-native-audio-api:downloadPrebuiltBinaries FAILED

> Task :posthog-react-native-session-replay:generateCodegenSchemaFromJavaScript                                                                                                                                                     
No modules to process in combine-js-to-schema-cli. If this is unexpected, please check if you set up your NativeComponent correctly. See combine-js-to-schema.js for how codegen finds modules.                                     

[Incubating] Problems report is available at: file:///D:/Git/Tencent/odin-client/android/build/reports/problems/problems-report.html

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':react-native-audio-api:downloadPrebuiltBinaries'.
> A problem occurred starting process 'command 'bash''

处理过程

根本原因:这个下载任务是通过一个脚本来执行的,而这个脚本需要 bash 这个命令行工具来运行。你的 Windows 系统默认没有 bash,所以 Gradle 尝试调用 bash 时,系统告诉它"找不到这个命令",于是整个任务就失败了

通常需要在 Unix-like 环境(如 Linux, macOS, 或者 Windows 上的 Git Bash)中通过 bash 来执行

1.安装 Git for Windows (如果你还没装)

如果你已经安装了,请跳到第二步

如果没有,请从下载并安装,在安装过程中,务必在 "Adjusting your PATH environment" 这一步,选择 "Git from the command line and also from 3rd-party software" 这个选项会将 bash.exe 所在的目录(默认是 C:\Program Files\Git\bin)添加到系统的 Path 环境变量中

2.验证 Path 环境变量

打开 Windows 搜索,输入 "环境变量",选择 "编辑系统环境变量",点击 "环境变量..." 按钮

在 "系统变量" 区域,找到 Path 变量,双击它,在弹出的列表中,仔细检查是否存在类似

C:\Program Files\Git\bin 或 C:\Program Files\Git\usr\bin 的条目

如果没有,你需要手动添加它

点击"新建",然后把你的 Git 安装目录下的 bin 文件夹路径粘贴进去

如果有,那么配置本身是正确的

如何验证?Windows 下打开 CMD 执行如下命令

bash 复制代码
Microsoft Windows [版本 10.0.26100.7462]
(c) Microsoft Corporation。保留所有权利。

C:\Users\Engineer-jsp>bash --version
GNU bash, version 5.2.26(1)-release (x86_64-pc-msys)
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

3.重启,让环境变量生效(最关键)

环境变量的修改不会影响已经打开的终端窗口

请完全关闭你所有的终端、PowerShell、CMD 窗口

请完全退出并重新打开你的代码编辑器(VS Code)

4.在新终端中验证

打开一个全新的 PowerShell 或 CMD 窗口

输入以下命令并回车: bash --version或者,对于 Windows CMD/PowerShell,可以使用 where 命令来查找 bash 的位置: where bash3.检查输出

如果 bash --version 成功打印出版本号,或者 where bash 成功打印出路径(如 C:\Program Files\Git\bin\bash.exe),那么恭喜你,你的环境已经准备好了!

如果 仍然提示"不是内部或外部命令",说明 Path 环境变量没有设置正确或没有生效,请回到第二、三步仔细检查

如:

bash 复制代码
C:\Users\Engineer-jsp>bash --version                                                                                    
GNU bash, version 5.2.26(1)-release (x86_64-pc-msys)                                                                    
Copyright (C) 2022 Free Software Foundation, Inc.                                                                       
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>                                           
                                                                                                                        
This is free software; you are free to change and redistribute it.                                                      
There is NO WARRANTY, to the extent permitted by law.                                                                   
                                                                                                                        
C:\Users\Engineer-jsp>where bash                                                                                        
D:\Git\Git\usr\bin\bash.exe 

5.清理并重新构建

在确认 bash 环境可用后,为了保险起见,进行一次清理

进入 android 目录并执行 clean 任务: cd android;./gradlew clean; cd .../

重新运行构建命令: bun run android

相关推荐
PnZh0Y12 小时前
python代码练习1
开发语言·python·算法
sheji34162 小时前
【开题答辩全过程】以 基于python的图书销售数据可视化系统为例,包含答辩的问题和答案
开发语言·python·信息可视化
_Soy_Milk2 小时前
【算法工程师】—— Python 高级
开发语言·python·算法
程序猿Code2 小时前
groovy闭包
开发语言·python
2401_861412142 小时前
python 从入门到精通 高清PDF 背记手册
开发语言·python·pdf
lsx2024062 小时前
jEasyUI 条件设置行背景颜色
开发语言
飞天小蜈蚣2 小时前
python-django_ORM的十三个查询API接口
开发语言·python·django
飞雪20072 小时前
局域网服务发现技术, DNS-SD和mDNS具体有什么区别, 什么不同?
开发语言·局域网·mdns·airplay·dns-sd·airprint
开开心心就好2 小时前
打印机驱动搜索下载工具,自动识别手动搜
java·linux·开发语言·网络·stm32·物联网·电脑