简体   繁体   English

在Android中构建本地本机应用程序时出错:SDK目录不存在

[英]Error building react-native first app in Android: The SDK directory does not exist

I'm getting this error when I try to run a React Native template app: 当我尝试运行React Native模板应用程序时出现此错误:

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.安装此:

  • brew install node brew安装节点
  • brew install watchman 酿造安装看守
  • brew tap AdoptOpenJDK/openjdk 酿造水龙头AdoptOpenJDK / openjdk
  • brew cask install adoptopenjdk8 酿造桶安装采用openjdk8

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: 我这样做是为了确保安装这些:

  • Android 9 (Pie) Android 9(派)
  • Android SDK Platform 28 Android SDK平台28
  • Intel x86 Atom_64 System Image (AND) Google APIs Intel x86 Atom System Image 英特尔x86 Atom_64系统映像(AND)Google API英特尔x86 Atom系统映像
  • Next, select the "SDK Tools" tab and check the box next to "Show Package Details" here as well. 接下来,选择“ SDK工具”选项卡,并在此处选中“显示软件包详细信息”旁边的框。 Look for and expand the "Android SDK Build-Tools" entry, then make sure that 28.0.3 is selected. 查找并展开“ Android SDK Build-Tools”条目,然后确保选择28.0.3。

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配置文件中:

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

(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环境变量

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

(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.

相关问题 构建 Android 应用程序时出现 React-Native 可绘制错误 - React-Native drawable error when building the Android app react-native run-android 构建错误 ':app:generateDebugBuildConfig' - react-native run-android Building Error ':app:generateDebugBuildConfig' Android react-native中的MainActivity不存在错误 - MainActivity does not exist error in Android react-native Mac 上的 React Native:SDK 目录“/Users/username/Library/Android/sdk”不存在 - React Native on Mac: The SDK directory '/Users/username/Library/Android/sdk' does not exist 运行 React-native 的 AwsomeProject 的调试目录不存在错误 - debug directory does not exist error running React-native's AwsomeProject 将Native android SDK集成到React-Native应用程序中 - Integrate Native android sdk into React-Native app 使用 react-native run-android 构建应用程序时出错 - Error when building app using react-native run-android react-native deploy到android设备错误3活动类不存在 - react-native deploy to android device error 3 activity class does not exist React-Native:错误类型 3:活动 class 不存在 - React-Native: Error type 3: Activity class does not exist 为什么在实现facebook sdk之后构建本机响应Android应用程序会给我这些错误? - Why does building my native react android app after implementing facebook sdk gives me these errors?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM