2

我开始学习如何在 android 环境中使用 ReactNative 进行移动编程。我正在使用 MacOS Catalina,并且已经安装了 android studio 和 react-native-cli。我跑react-native init ShoppingList过去了

Downloading template, 
Copying template, 
Processing template 

但失败了,Installing CocoaPods dependencies因为我还没有使用最新的操作系统(我希望这不是问题的一部分,因为我没有足够的内存来升级操作系统)

我在这个问题中提到了一个建议,它要求我运行

npm uninstall -g react-native react-native-cli
npm install -g react-native react-native-cli
react-native start --reset-cache

我还删除了 node_modules 和npm install项目的根目录。然后在我运行的项目的根目录下react-native run-android

这给了我以下错误

info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 967 file(s) to forward-jetify. Using 8 workers...
info Starting JS server...
/bin/sh: adb: command not found
info Launching emulator...
error Failed to launch emulator. Reason: No emulators found as an output of `emulator -list-avds`.
warn Please launch an emulator manually or connect a device. Otherwise app may fail to launch.
info Installing the app...

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.2/userguide/command_line_interface.html#sec:command_line_warnings

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':app:installDebug'.
> SDK location not found. Define location with an ANDROID_SDK_ROOT environment variable or by setting the sdk.dir path in your project's local properties file at '/Users/prashin/Test/ShoppingList/android/local.properties'.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 2s

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Run CLI with --verbose flag for more details.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081

在 Android Studio 内部,安装了以下内容

Android 11.0(R),
Android SDK Build-Tools, 
Android Emulator 30.2.6, 
Android SDK-Platform-Tools 30.0.5, 
Intel x86 Emulator Accelerator (HAXM installer) 7.5.1

Pixel 2 Device我用)创建了一个Release name R(API Level 30,并无数次按下播放按钮,它给了我的错误AVD Manager: Unable to locate ADB

这是我的.bash_profile文件。

source ~/.profile

# Setting PATH for Python 3.7
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.7/bin:${PATH}"
export PATH

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

##
# Your previous /Users/prashin/.bash_profile file was backed up as /Users/prashin/.bash_profile.macports-saved_2019-10-23_at_18:32:04
##

# MacPorts Installer addition on 2019-10-23_at_18:32:04: adding an appropriate PATH variable for use with MacPorts.
export PATH="/opt/local/bin:/opt/local/sbin:$PATH"
export ANDROID_HOME=/Users/prashin/Library/Android/sdk
export ANDROID_SDK_ROOT=$ANDROID_HOME
export PATH="$PATH:$ANDROID_HOME/emulator:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools"
# export PATH="$PATH:/Users/$USER/Library/Android/sdk/platform-tools"
# export PATH=${PATH}:/usr/local/mysql-5.7.31-macos10.14-x86_64/bin
# Finished adapting your PATH environment variable for use with MacPorts.

根据这篇文章,我确实在平台工具中看到了一个 adb 可执行文件。

我可能会在这里遗漏什么阻止我在模拟器上运行我的基本应用程序?如果需要更多信息,请通知我。

编辑

建议的切换解决方案.zprofile改为更改错误消息。info launching emulator在产生以下错误之前,它卡住了 30 秒。

error Failed to launch emulator. Reason: Could not start emulator within 30 seconds..
warn Please launch an emulator manually or connect a device. Otherwise app may fail to launch.
info Installing the app...

> Task :app:stripDebugDebugSymbols UP-TO-DATE
Compatible side by side NDK version was not found.

> Task :app:installDebug FAILED
Skipping device 'emulator-5554' (emulator-5554): Device is OFFLINE.

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.2/userguide/command_line_interface.html#sec:command_line_warnings
27 actionable tasks: 2 executed, 25 up-to-date

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:installDebug'.
> com.android.builder.testing.api.DeviceException: No online devices found.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 4s

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Run CLI with --verbose flag for more details.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
4

2 回答 2

0

只需重新启动终端对我来说就是诀窍......

于 2021-05-01T21:33:09.613 回答
0

对于 Catalina,Apple 已将默认 shell 更改为 zsh。因此,您必须重命名配置文件。 .bashrc 现在 .zshrc 和 .bash_profile 现在 .zprofile。将您的内容移动.bash_profile到新.zprofile文件并重新启动终端。使用新的环境变量再次运行应用程序。

于 2020-12-03T18:10:30.883 回答