试图在Mac M1上构建Android的React Antive App-错误:未发现仿真器作为“模拟器-list -avds”的输出

发布于 2025-01-23 10:18:31 字数 2298 浏览 1 评论 0原文

我已经在Mac M1上安装了Android Studio
我使用设备管理器在Android Studio中添加了一个虚拟设备
该应用程序从Android Studio内部构建正常...但是,当我从vscode中的命令行运行npx react-npt-intage-nrative and-android时,我得到了错误no模拟器模拟器的输出-list -avds

但是,当我使用cd〜/library/android/sdk/emulator和运行命令./ emulator -avd {avd_name}时,使用cd〜/android/sdk/emulator 时,模拟器开始时,模拟器启动良好.. ...但是,即使在模拟器运行时,命令npx react-native-native android仍然给出了错误no模拟器作为模拟器-list-list-avds <<br>

更新04/26 - 我遵循@qqnade的说明,但是我仍然遇到同样的错误...请参阅下面的屏幕截图:

仅从上面的屏幕截图中注意到错误

/bin/sh: adb: command not found

..也是,当我在终端运行echo $ path时,我会得到以下响应:
/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/bin:/usr/sbin:/sbin:/sbin:/library/apple/apple/usr/bin

我在其中没有任何对Android的引用,所以我认为那不是一件好事

更新04/26#2
我添加了一个〜/.zshrc文件,并按照下面的填充:

export ANDROID_HOME="$HOME/Library/Android/sdk"
export 
PATH="$ANDROID_HOME/tools:$ANDROID_HOME/tools/bin:$ANDROID_HOME/platform-tools:$PATH"

..该求解/bin/sh:adb:adb:command ofer现在我有一个新的:

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: spawn ./gradlew EACCES
    at Process.ChildProcess._handle.onexit (node:internal/child_process:283:19)
    at onErrorNT (node:internal/child_process:476:16)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)

....至少它现在启动模拟器

更新04/26#3
许多SO帖子告诉我,从Android文件夹(然后清洁)运行以下命令

chmod +x gradlew;

...现在我遇到了一个不同的错误:

Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
./gradlew: line 188: syntax error: unexpected end of file

我想知道这是否与我最初在Windows上创建该应用程序有关的事实是否有任何关系。 ...这是我第一次试图在Mac上建立吗?
我在VSCODE中检查了Gradlew文件,它显示为LF(不是CRLF),我知道,在为Mac构建时,它是正确的

I have installed Android Studio on my mac M1
I have added a virtual device in Android Studio using Device Manager
The app builds fine from inside Android Studio......however when I run npx react-native run-android from command line in VSCode, I get the error No emulators found as an output of emulator -list-avds

However when I navigate to emulator folder using cd ~/Library/Android/sdk/emulator and run command ./emulator -avd {AVD_NAME}, the emulator starts fine.....however even with the emulator running, the command npx react-native run-android still gives the error No emulators found as an output of emulator -list-avds

UPDATE 04/26 - I followed instructions from @qqNade, however I am still getting same error...see screenshot below:
enter image description here

Just noticed from the screenshot above, the error

/bin/sh: adb: command not found

..also, when I run echo $PATH in terminal, I get the following response:
/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin

I dont see any reference to android in there, so I assume thats not a good thing

UPDATE 04/26 #2
I added a ~/.zshrc file and populated it as per below:

export ANDROID_HOME="$HOME/Library/Android/sdk"
export 
PATH="$ANDROID_HOME/tools:$ANDROID_HOME/tools/bin:$ANDROID_HOME/platform-tools:$PATH"

..that solved the /bin/sh: adb: command not found error, but now I have a new one:

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: spawn ./gradlew EACCES
    at Process.ChildProcess._handle.onexit (node:internal/child_process:283:19)
    at onErrorNT (node:internal/child_process:476:16)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)

....at least its launching the emulator now

UPDATE 04/26 #3
A number of SO posts told me to run the following command from android folder (and then clean)

chmod +x gradlew;

...now Im getting a different error:

Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
./gradlew: line 188: syntax error: unexpected end of file

Im wondering if this has anything to do with fact that I created the app originally on Windows.....and this is the first time Im trying to build on Mac?
I checked gradlew file in VSCode and its showing as LF (not CRLF) which as I understand it is correct when building for Mac

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

渡你暖光 2025-01-30 10:18:31

需要打开命令提示

nano ~/.zsh_profile

export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools

我还遇到了一个问题,要解决它,

source $HOME/.zsh_profile

I also faced such a problem, to solve it you need to open a command prompt and enter

nano ~/.zsh_profile

after which you need to add this to the file and save

export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools

then enter on the command line

source $HOME/.zsh_profile
清秋悲枫 2025-01-30 10:18:31

我想帮助你。

您在主目录中(可以使用CD $ HOME或CD〜)

export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools

source ~/.bash_profile (or source ~/.zshrc, take a look at my note at the end please)

之后,当您执行命令vi .bash_profile(或vi .zshrc)之后,

,您应该看到类似的东西

在这一点上,您可以尝试再次执行模拟器-list-avds命令

,是的,echo $ path应该向您显示与Android相关的条目,例如〜/library/android/android/sdk/plancept-tools

echo echo $ android_home,

即使不是工作,我将尝试导航到Android文件夹,并在一个时间下运行命令

chmod +x gradlew
./gradlew clean
react-native run-android

:请确保Mac在下面的命令中使用哪个Shell。

echo $0

进一步阅读

设置开发环境

I want to help you.

You're in the home directory (you can go there with cd $HOME or cd ~)

export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools

source ~/.bash_profile (or source ~/.zshrc, take a look at my note at the end please)

After that, when you execute command vi .bash_profile (or vi .zshrc), you should see something like that

enter image description here

At this point, you can try to execute emulator -list-avds command again

And yes, echo $PATH should show you entries related with Android like ~/Library/Android/sdk/platform-tools

echo $ANDROID_HOME as well

If still not working, I would try to navigate to android folder and run the commands below one more time

chmod +x gradlew
./gradlew clean
react-native run-android

NOTE: Please be sure which shell your mac is using with the command below.

echo $0

Further reading

setting up development environment

残龙傲雪 2025-01-30 10:18:31

我已经用自制的设置

echo $ path

/bin:/usr/bin:/usr/usr/local/bin:/opt/homebrew/bin:/opt/opt/homebrew/sbin:/usr/usr/local/bin:/usr/bin:/usr/bin :/bin:/usr/sbin:/sbin:/library/apple/usr/bin:/useres/username/username/library/android/sdk/emulator:/useler/useername/username/library/android/android/sdk/platform-

tools获取此错误,

错误无法安装该应用程序。 Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup
错误:Spawn ./gradlew eacces
at Process.ChildProcess._handle.Onexit(node:internal/child_process:283:19)
在Onerrornt(节点:内部/child_process:476:16)
在processTickSandRepoxtions(节点:内部/process/task_queues:83:21)

尝试运行此命令,它将使用访问权限更新Gradlew文件,这是M1芯片计算机仅

CD Android

Chmod +X Gradlew,

这解决了我的问题

I have used homebrew for setting up

echo $PATH

/bin:/usr/bin:/usr/local/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Users/userName/Library/Android/sdk/emulator:/Users/userName/Library/Android/sdk/platform-tools

when we get this error,

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: spawn ./gradlew EACCES
at Process.ChildProcess._handle.onexit (node:internal/child_process:283:19)
at onErrorNT (node:internal/child_process:476:16)
at processTicksAndRejections (node:internal/process/task_queues:83:21)

try running this command and it will update the gradlew file with access permission, this is for M1 chip machine only

cd android

chmod +x gradlew

This solved my issue

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文