简体   繁体   English

为什么构建适用于 ios 而不适用于 android? 反应原生

[英]why is the build working for ios but not android? React native

I just created a new project with react native, I downloaded homebrew, Android Studio, and Watchman but I still cant build my project on the virtual device.我刚刚用 react native 创建了一个新项目,我下载了 homebrew、Android Studio 和 Watchman,但我仍然无法在虚拟设备上构建我的项目。 It works on IOS from the moment the project was created but not Android.从项目创建的那一刻起,它就适用于 IOS,但不适用于 Android。

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':app'.
> 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/cal/Solvicles/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

According from the docs :根据文档

Have you tried adding the ANDROID_HOME environment variable to $HOME/.bash_profile ?您是否尝试将ANDROID_HOME环境变量添加到$HOME/.bash_profile If not, go ahead and add it to your .bash_profile (or create if the file doesn't exists) in your home ~ directory.如果没有,请继续将其添加到您的 home ~目录中的.bash_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

Then restart the terminal and try to run it again.然后重新启动终端并尝试再次运行它。

To make sure your environment is setup properly for android, go to the root of your react-native project.要确保您的环境已为 android 正确设置,请转到 react-native 项目的根目录。 Open the android project(folder) in the Android Studio IDE.在 Android Studio IDE 中打开 android 项目(文件夹)。

All errors with your environment will show up, and that will automatically start the Gradle Daemon to sync and configure the build for you.您的环境中的所有错误都会显示出来,并且会自动启动 Gradle 守护程序来为您同步和配置构建。 Once it finished, close the Android Studio and come back to command-line and run: react-native run-android完成后,关闭 Android Studio 并返回命令行并运行: react-native run-android

And dont forget to execute below thingsfor android home path variable :并且不要忘记为 android 主路径变量执行以下内容:

The React Native tools require some environment variables to be set up in order to build apps with native code. React Native 工具需要设置一些环境变量才能使用本机代码构建应用程序。

Add the following lines to your $HOME/.bash_profile or $HOME/.bashrc config file:将以下行添加到您的 $HOME/.bash_profile 或 $HOME/.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

.bash_profile is specific to bash. .bash_profile 特定于 bash。 If you're using another shell, you will need to edit the appropriate shell-specific config file.如果您使用另一个 shell,则需要编辑相应的特定于 shell 的配置文件。

Type source $HOME/.bash_profile to load the config into your current shell.输入 source $HOME/.bash_profile 以将配置加载到您当前的 shell 中。 Verify that ANDROID_HOME has been added to your path by running echo $PATH.通过运行 echo $PATH 验证 ANDROID_HOME 是否已添加到您的路径中。

Please make sure you use the correct Android SDK 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 Studio 的“首选项”对话框的外观和行为 → 系统设置 → Android SDK 下找到 SDK 的实际位置。

Hope it helps.希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM