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

相关推荐
郑州光合科技余经理5 天前
代码展示:PHP搭建海外版外卖系统源码解析
java·开发语言·前端·后端·系统架构·uni-app·php
feifeigo1235 天前
matlab画图工具
开发语言·matlab
dustcell.5 天前
haproxy七层代理
java·开发语言·前端
norlan_jame5 天前
C-PHY与D-PHY差异
c语言·开发语言
多恩Stone5 天前
【C++入门扫盲1】C++ 与 Python:类型、编译器/解释器与 CPU 的关系
开发语言·c++·人工智能·python·算法·3d·aigc
QQ4022054965 天前
Python+django+vue3预制菜半成品配菜平台
开发语言·python·django
遥遥江上月5 天前
Node.js + Stagehand + Python 部署
开发语言·python·node.js
m0_531237175 天前
C语言-数组练习进阶
c语言·开发语言·算法
Railshiqian5 天前
给android源码下的模拟器添加两个后排屏的修改
android·开发语言·javascript
雪人不是菜鸡5 天前
简单工厂模式
开发语言·算法·c#