[英]Error building react-native first app in Android: The SDK directory does not exist
FAILURE: Build failed with an exception.
失败:构建失败,发生异常。
What went wrong: A problem occurred configuring project ':app'.
出了什么问题:配置项目':app'时发生问题。 The SDK directory '/home/[USER]/Android/Sdk' does not exist.
SDK目录“ / home / [USER] / Android / Sdk”不存在。
I've followed the Get Started Guide by React Native, step by step ( https://facebook.github.io/react-native/docs/getting-started ) 我已经按照React Native的入门指南进行了逐步操作 ( https://facebook.github.io/react-native/docs/getting-started )
1. Installed this: 1.安装此:
2. And this: 2.并且:
npm install -g react-native-cli npm install -g react-native-cli
3. Also did this: 3.还这样做:
Install Android Studio Download and install Android Studio. 安装Android Studio下载并安装Android Studio。 Choose a "Custom" setup when prompted to select an installation type.
当提示您选择安装类型时,请选择“自定义”设置。 Make sure the boxes next to all of the following are checked:
确保选中以下所有框旁边的框:
Android SDK Android SDK Platform Performance (Intel ® HAXM) (See here for AMD) Android Virtual Device Android SDK Android SDK平台性能(Intel®HAXM)(有关AMD,请参见此处)Android虚拟设备
I did it making sure to install these: 我这样做是为了确保安装这些:
4. Then, I did this with vim $HOME/.bash_profile 4.然后,我使用vim $ HOME / .bash_profile进行了此操作
Add the following lines to your $HOME/.bash_profile or $HOME/.bashrc config file: 将以下行添加到$ HOME / .bash_profile或$ HOME / .bashrc配置文件中:
(Do not copy paste the bullets) (请勿复制粘贴项目符号)
BUT 但
I did not get this: 我没有得到这个:
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添加到您的路径。
When I do echo $PATH, I see this: 当我回显$ PATH时,我看到以下内容:
/opt/local/bin:/opt/local/sbin:/Library/Frameworks/Python.framework/Versions/3.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/hectorgonzalezsanchez/Library/Android/sdk/emulator:/Users/hectorgonzalezsanchez/Library/Android/sdk/tools:/Users/hectorgonzalezsanchez/Library/Android/sdk/tools/bin:/Users/hectorgonzalezsanchez/Library/Android/sdk/platform-tools / opt /本地/bin:/opt/local/sbin:/Library/Frameworks/Python.framework/Versions/3.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/ sbin:/用户/ hectorgonzalezsanchez /库/ Android / sdk /模拟器:/用户/ hectorgonzalezsanchez /库/ Android / sdk /工具:/ Users / hectorgonzalezsanchez / Library / Android / sdk / tools / bin:/用户/ hectorgonzalez Android / SDK /平台工具
When I do vim $HOME/.bash_profile, I see this: 当我执行$ HOME / .bash_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 设置Python 3.7的PATH原始版本保存在.bash_profile.pysave PATH =“ / Library / Frameworks / Python.framework / Versions / 3.7 / bin:$ {PATH}”导出路径中
Your previous /Users/hectorgonzalezsanchez/.bash_profile file was backed up as /Users/hectorgonzalezsanchez/.bash_profile.macports-saved_2019-08-15_at_13:26:28 您先前的/Users/hectorgonzalezsanchez/.bash_profile文件已备份为/Users/hectorgonzalezsanchez/.bash_profile.macports-saved_2019-08-15_at_13:26:28
MacPorts Installer addition on 2019-08-15_at_13:26:28: adding an appropriate PATH variable for use with MacPorts. MacPorts安装程序于2019-08-15_at_13:26:28新增:添加了一个适当的PATH变量以用于MacPorts。 export PATH="/opt/local/bin:/opt/local/sbin:$PATH" Finished adapting your PATH environment variable for use with MacPorts.
export PATH =“ / opt / local / bin:/ opt / local / sbin:$ PATH”完成调整PATH环境变量以用于MacPorts。
Adding ANDROID_HOME enviroment variable 添加ANDROID_HOME环境变量
(Do not copy paste the bullets) (请勿复制粘贴项目符号)
When I do echo $HOME, I see this: 当我回显$ HOME时,我看到以下内容:
/Users/hectorgonzalezsanchez /用户/ hectorgonzalezsanchez
I created an app: 我创建了一个应用程序:
react-native init FirstApp 反应本机的FirstApp
And ran it with iOS: 并在iOS上运行:
'cd FirstApp react-native run-ios' 'cd FirstApp react-native run-ios'
AND WAS SUCCESFUL (no problem in iPhone X with XCode) 并且成功(在使用XCode的iPhone X中没有问题)
BUT when I do: 但是当我这样做时:
'cd FirstApp' 'react-native run-android' 'cd FirstApp''本机运行Android'
I get this error message: 我收到此错误消息:
What went wrong: A problem occurred configuring project ':app'. 出了什么问题:配置项目':app'时发生问题。 The SDK directory '/home/[USER]/Android/Sdk' does not exist.
SDK目录“ / home / [USER] / Android / Sdk”不存在。
Try: Run with --stacktrace option to get the stack trace. 尝试:使用--stacktrace选项运行以获取堆栈跟踪。 Run with --info or --debug option to get more log output.
使用--info或--debug选项运行以获取更多日志输出。 Run with --scan to get full insights.
与--scan一起运行以获取完整的见解。
Get more help at https://help.gradle.org 在https://help.gradle.org上获得更多帮助
BUILD FAILED in 2s 2秒内失败
error Failed to install the app. 错误无法安装应用程序。 Make sure you have the Android development environment set up: https://facebook.github.io/react-native/docs/getting-started.html#android-development-environment .
确保您已设置Android开发环境: https : //facebook.github.io/react-native/docs/getting-started.html#android-development-environment 。 Run CLI with --verbose flag for more details.
使用--verbose标志运行CLI以获取更多详细信息。 Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
错误:命令失败:./ gradlew app:installDebug -PreactNativeDevServerPort = 8081
I tried several "solutions" given in other threads, as making a local.properties in the FirstApp/android/ folder as follows: 我尝试了其他线程中给出的几种“解决方案”,如下所示在FirstApp / android /文件夹中创建了local.properties:
sdk.dir = /Users/hectorgonzalezsanchez/Library/Android/Sdk sdk.dir = / Users / hectorgonzalezsanchez / Library / Android / SDK
**At this point I realized that I did not set up the virtual device properly in Android Studio before running... **至此,我意识到我在运行之前没有在Android Studio中正确设置虚拟设备...
I did this EXACTLY as it is written, and was a TOTAL SUCCESS!!!!!** 我写的时候完全做到了,而且完全成功了!!!!
Using a virtual device If you use Android Studio to open ./AwesomeProject/android, you can see the list of available Android Virtual Devices (AVDs) by opening the "AVD Manager" from within Android Studio. 使用虚拟设备如果您使用Android Studio打开./AwesomeProject/android,则可以通过从Android Studio中打开“ AVD管理器”来查看可用的Android虚拟设备(AVD)的列表。 Look for an icon that looks like this:
查找看起来像这样的图标:
Android Studio AVD Manager Android Studio AVD管理器
If you have just installed Android Studio, you will likely need to create a new AVD. 如果您刚刚安装了Android Studio,则可能需要创建一个新的AVD。 Select "Create Virtual Device...", then pick any Phone from the list and click "Next", then select the Pie API Level 28 image.
选择“创建虚拟设备...”,然后从列表中选择任何电话,然后单击“下一步”,然后选择Pie API Level 28图像。
If you don't have HAXM installed, follow these instructions to set it up, then go back to the AVD Manager. 如果您尚未安装HAXM,请按照以下说明进行设置,然后返回到AVD管理器。
Click "Next" then "Finish" to create your AVD. 单击“下一步”,然后单击“完成”以创建您的AVD。 At this point you should be able to click on the green triangle button next to your AVD to launch it, then proceed to the next step.
此时,您应该可以单击AVD旁边的绿色三角形按钮以启动它,然后继续进行下一步。
(WAIT until the Android virtual device interface is initated and fully operative to run the following) (请等待,直到启动了Android虚拟设备界面并可以完全运行以下命令)
cd FirstApp react-native run-android cd FirstApp react-native运行Android
TADAAAAA 塔达阿
In my path to describe my actions here I found the solutions myself. 在这里描述我的行动的过程中,我自己找到了解决方案。
Thanks, Stackoverflow. 谢谢,Stackoverflow。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.