简体   繁体   English

验证 ANDROID_HOME 是否已添加到您的路径中

[英]Verify that ANDROID_HOME has been added to your path

I am trying to set up react-native (for Android) on my macOs but the app is failing to build so I am retrying it by following this link:我正在尝试在我的 macOS 上设置 react-native(适用于 Android),但该应用程序无法构建,因此我正在通过以下链接重试:

https://reactnative.dev/docs/environment-setup https://reactnative.dev/docs/environment-setup

In one of the steps, we have to add something to our $HOME/.bash_profile .在其中一个步骤中,我们必须在$HOME/.bash_profile中添加一些内容。 I open it using vi.bash_profile and then paste the commands.我使用vi.bash_profile打开它,然后粘贴命令。 Next, I am asked to 'Verify that ANDROID_HOME has been added to your path by running echo $PATH.接下来,我被要求'通过运行echo $PATH. ' '

When I run echo $PATH.当我运行echo $PATH. , I get this: ,我明白了:

/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/share/dotnet:~/.dotnet/tools:/Library/Apple/usr/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Users//Library/Android/sdk/emulator:/Users//Library/Android/sdk/tools:/Users//Library/Android/sdk/tools/bin:/Users//Library/Android/sdk/platform-tools /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/share/dotnet:~/.dotnet/tools:/Library/Apple/usr/bin:/Library /Frameworks/Mono.framework/Versions/Current/Commands:/Users//Library/Android/sdk/emulator:/Users//Library/Android/sdk/tools:/Users//Library/Android/sdk/tools/bin :/用户//库/Android/sdk/platform-tools

I don't see the word ANDROID_HOME anywhere.我在任何地方都没有看到 ANDROID_HOME 这个词。 Is there a problem here?这里有问题吗? Maybe with the path?也许与路径? Or is it being correctly verified?或者它是否被正确验证?

I am running this in the root directory.我在根目录中运行它。

EDIT:编辑:

I managed to successfully setup everything and run the default AwesomeProject as well (from the root directory).我设法成功设置了所有内容并运行了默认的 AwesomeProject(从根目录)。 However, when I try to run another project, it does not work.但是,当我尝试运行另一个项目时,它不起作用。 I see this:我看到这个:

SDK location not found.未找到 SDK 位置。 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/mycompany/insta/app/android/local.properties使用 ANDROID_SDK_ROOT 环境变量或通过在项目的本地属性文件中设置 sdk.dir 路径来定义位置 '/Users/mycompany/insta/app/android/local.properties

What's the problem?有什么问题? Which steps from the setup should I repeat inside this particular folder?我应该在这个特定文件夹中重复设置中的哪些步骤? Should I make another bash profile?我应该制作另一个 bash 配置文件吗? I don't get what path to add in the local.properties我没有在 local.properties 中添加什么路径

Your PATH variable is being correctly modified.您的PATH变量正在被正确修改。

Echo your ANDROID_HOME variable to see what it is.回显您的ANDROID_HOME变量以查看它是什么。 It should be /Users//Library/Android/sdk/ .它应该是/Users//Library/Android/sdk/ When you use this variable in PATH , it's automatically being expanded when you echo it.当您在PATH中使用此变量时,它会在您回显时自动扩展。 You won't see "ANDROID_HOME" in the PATH.您不会在 PATH 中看到“ANDROID_HOME”。

You can find all the environment variable documentation here: https://developer.android.com/studio/command-line/variables您可以在此处找到所有环境变量文档: https://developer.android.com/studio/command-line/variables

According to the dev website:根据开发网站:

If ANDROID_HOME is defined and contains a valid SDK installation, its value is used instead of the value in ANDROID_SDK_ROOT.如果 ANDROID_HOME 已定义并包含有效的 SDK 安装,则使用其值而不是 ANDROID_SDK_ROOT 中的值。

If ANDROID_HOME is not defined, the value in ANDROID_SDK_ROOT is used.如果未定义 ANDROID_HOME,则使用 ANDROID_SDK_ROOT 中的值。

If ANDROID_HOME is defined but does not exist or does not contain a valid SDK installation, the value in ANDROID_SDK_ROOT is used instead.如果 ANDROID_HOME 已定义但不存在或不包含有效的 SDK 安装,则使用 ANDROID_SDK_ROOT 中的值。

Try echo $ANDROID_HOME .尝试echo $ANDROID_HOME If that returns nothing try echo $ANDROID_SDK_ROOT .如果没有返回任何内容,请尝试echo $ANDROID_SDK_ROOT One of them should return your SDK directory.其中之一应该返回您的 SDK 目录。 If not export one of them in your bash_profile as a env variable.如果不在bash_profile中将其中一个导出为 env 变量。

Easiest solution is to do a quick install of Android Studio and selecting the option to install SDK tools.最简单的解决方案是快速安装 Android Studio 并选择安装 SDK 工具的选项。 This easily sets up your environment for android.这很容易为 android 设置您的环境。 All you need to do is add the SDK tools directory to your path once the install completes.安装完成后,您需要做的就是将 SDK 工具目录添加到您的路径中。

AVD images are pedantic if you change any directories and throw SDK_ROOT errors if you change things.如果您更改任何目录并抛出 SDK_ROOT 错误,则 AVD 图像是迂腐的。 Most problem free solution is to either download and run the installer or download the SDK tools, run the install and specify the path directory.大多数无问题的解决方案是下载并运行安装程序或下载 SDK 工具,运行安装并指定路径目录。

create local.properties file inside android folder and paste sdk.dir={ANDROID_SDK_PATH} , then restart react-native server.在 android 文件夹中创建local.properties文件并粘贴sdk.dir={ANDROID_SDK_PATH} ,然后重新启动 react-native 服务器。

This problem has to do with two things:这个问题与两件事有关:

  1. local.properties file local.properties 文件

  2. ANDROID_HOME (SDK path) ANDROID_HOME(SDK 路径)

Firstly, For the local.properties, first make sure that the file is there in your project folder/android.首先,对于 local.properties,首先确保该文件在您的项目文件夹/android 中。 If the file is there open it and make sure that the sdk.dir is pointing to your android SDK directory.如果文件在那里,请打开它并确保sdk.dir指向您的 android SDK 目录。

and if the file is not there create it and paste this:如果文件不存在,请创建它并粘贴:

sdk.dir = /Users/USERNAME/Library/Android/sdk

Replace USERNAME with your usernameUSERNAME替换为您的用户名

Secondly, make sure that the ANDROID_HOME is there in the system variables and is also pointing to your android SDK directory.其次,确保ANDROID_HOME存在于系统变量中,并且还指向您的 android SDK 目录。

or create new system variable named ANDROID_HOME and set the value your android SDK directory path if it's not there或创建名为ANDROID_HOME的新系统变量,并设置 android SDK 目录路径的值(如果不存在)

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

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