![](/img/trans.png)
[英]React Native release apk doesn't match app when running react-native run-android
[英]npx react-native run-android doesn't start emulator and doesn't run if emulator is running
我使用 react-native 0.63 创建了一个新项目,当我在 ios 模拟器上运行时一切正常,但是当尝试在 android 上运行时,它不起作用并给我这个错误
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 '/Volumes/SSD2/developer/MyProject/AwesomeProject/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
我安装 react-native 就像react-native 设置
这是我的 react-native 医生给我的 output
✓ Node.js
✓ npm
✓ Watchman - Used for watching changes in the filesystem when in development mode
Android
✓ JDK
✓ Android Studio - Required for building and installing your app on Android
✖ Android SDK - Required for building and installing your app on Android
- Versions found: N/A
- Version supported: 29.0.2
✖ ANDROID_HOME
iOS
✓ Xcode - Required for building and installing your app on iOS
✓ CocoaPods - Required for installing iOS dependencies
✓ ios-deploy - Required for installing your app on a physical device with the CLI
Errors: 2
Warnings: 0
如果我运行 npx react-native start 然后应用程序从 android 工作室顺利运行。
如果我从终端 source.bash_profile 运行项目,请编辑
模拟器启动但项目未运行
"--no-jetifier" flag.
Jetifier found 5194 file(s) to forward-jetify. Using 12 workers...
info JS server already running.
info Installing the app...
env: sh\r: No such file or directory
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
env: sh\r: No such file or directory
看起来您需要设置 ANDROID_HOME 环境变量。
将以下行添加到您的 $HOME/.bash_profile 或 $HOME/.bashrc(如果您使用的是 zsh,则使用 ~/.zprofile 或 ~/.zshrc)配置文件:
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
为 bash 键入 source $HOME/.bash_profile 或 source $HOME/.zprofile 将配置加载到您当前的 shell 中。 通过运行 echo $ANDROID_HOME 验证 ANDROID_HOME 是否已设置,并且通过运行 echo $PATH 已将适当的目录添加到您的路径中。
请确保使用正确的 Android SDK 路径。 You can find the actual location of the SDK in the Android Studio "Preferences" dialog, under Appearance & Behavior → System Settings → Android SDK.
参考:
配置 ANDROID_HOME 环境变量
React Native 工具需要设置一些环境变量才能使用本机代码构建应用程序。
Go 到主目录并显示隐藏文件,然后将以下行添加到您的~/.zprofile
或~/.zshrc
/.zshrc (如果您使用的是 bash 终端,则添加~/.bash_profile
或~/.bashrc
)配置文件:
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 ~/.zprofile
或source ~/.zshrc
/.zshrc(或source ~/.bash_profile
或source ~/.bashrc
for bash)以将配置加载到当前的 shell。通过运行 echo 验证是否已设置 ANDROID_HOME $ANDROID_HOME 和相应的目录已通过运行 echo $PATH 添加到您的路径中。
如果错误仍然存在,请重新启动系统。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.