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

相关推荐
Evand J2 分钟前
【代码介绍】自适应R的AEKF(自适应扩展卡尔曼滤波)和经典EKF比较,MATLAB例程|三维非线性系统
开发语言·matlab·ekf·自适应·自适应滤波
雪的季节10 分钟前
1 个网络线程 + 3 个数据处理线程(完全隔离)
开发语言
风筝在晴天搁浅11 分钟前
快手 CodeTop LeetCode 227.基本计算器Ⅱ
java·开发语言
0xDevNull16 分钟前
Java实战面试题(一)
java·开发语言
雪的季节24 分钟前
C++ 运行时多态 vs 编译时多态
开发语言
chushiyunen26 分钟前
php笔记、下载安装等
开发语言·笔记·php
闲猫27 分钟前
SSH 黑屏配置试用环境机器,受限bash和自定义shell
运维·ssh·bash
Xin_ye1008628 分钟前
C# 零基础到精通教程 - WPF 深度专题:自定义布局与性能优化
开发语言·c#·wpf
努力努力再努力wz28 分钟前
【C++高阶数据结构系列】:跳表 SkipList 详解:多层索引、随机晋升与C++ 完整实现(附跳表实现的源码)
开发语言·数据结构·数据库·c++·redis·缓存·skiplist
更深兼春远30 分钟前
scala基于IDEA部署
开发语言·scala·intellij-idea