当前位置: 首页 > 知识库问答 >
问题:

在运行“ns run”和“ns doctor Android”时获取“未设置Android_home环境变量”

万俟修诚
2023-03-14

我在用macOS。我以前已经在一个react-native项目中使用过Android Studio和Xcode。我现在正在学习苗条。当我开始跟踪这里和这里的文档,并进入需要运行NS doctor Android的步骤时,我得到了这个错误:

zeddrix@Zeddrixs-MacBook-Pro todoapp % ns doctor android
✔ Getting environment information 

TIP: To avoid setting up the necessary environment variables, you can use the Homebrew package manager to install the Android SDK and its dependencies.

There seem to be issues with your configuration.
✔ Getting NativeScript components versions information...
✔ Component nativescript has 8.1.2 version and is up to date.
⚠ Update available for component @nativescript/core. Your current version is 7.0.0 and the latest available version is 8.1.3.
⚠ Update available for component @nativescript/android. Your current version is 7.0.0 and the latest available version is 8.1.1.
✔ Javac is installed and is configured properly.
✔ The Java Development Kit (JDK) is installed and is configured properly.
✔ Xcode is installed and is configured properly.
✔ xcodeproj is installed and is configured properly.
✔ CocoaPods are installed.
✔ CocoaPods update is not required.
✔ CocoaPods are configured properly.
✔ Your current CocoaPods version is newer than 1.0.0.
✔ Python installed and configured correctly.
✔ The Python 'six' package is found.
✔ Xcode version 13.0.0 satisfies minimum required version 10.
✖ The ANDROID_HOME environment variable is not set or it points to a non-existent directory. You will not be able to perform any build-related operations for Android. 
 To be able to perform Android build-related operations, set the `ANDROID_HOME` variable to point to the root of your Android SDK installation directory. 

✖ WARNING: adb from the Android SDK is not installed or is not configured properly.  
 For Android-related operations, the NativeScript CLI will use a built-in version of adb.
To avoid possible issues with the native Android emulator, Genymotion or connected
Android devices, verify that you have installed the latest Android SDK and
its dependencies as described in http://developer.android.com/sdk/index.html#Requirements 

✖ WARNING: The Android SDK is not installed or is not configured properly. 
 You will not be able to run your apps in the native emulator. To be able to run apps
in the native Android emulator, verify that you have installed the latest Android SDK 
and its dependencies as described in http://developer.android.com/sdk/index.html#Requirements 

✖ Cannot find a compatible Android SDK for compilation. To be able to build for Android, install Android SDK 28 or later. 
 Run `$ sdkmanager` to manage your Android SDK versions. 

✖ You need to have the Android SDK Build-tools installed on your system. You can install any version in the following range: '>=23 <=30'. 
 Run `$ sdkmanager` from your command-line to install required `Android Build Tools`. In case you already have them installed, make sure `ANDROID_HOME` environment variable is set correctly. 

Cannot read property 'toLowerCase' of null
zeddrix@Zeddrixs-MacBook-Pro todoapp % 

我在运行ns run时也得到了这个:

zeddrix@Zeddrixs-MacBook-Pro todoapp % ns run
✔ Javac is installed and is configured properly.
✔ The Java Development Kit (JDK) is installed and is configured properly.
✖ The ANDROID_HOME environment variable is not set or it points to a non-existent directory. You will not be able to perform any build-related operations for Android. 
 To be able to perform Android build-related operations, set the `ANDROID_HOME` variable to point to the root of your Android SDK installation directory. 

✖ WARNING: adb from the Android SDK is not installed or is not configured properly.  
 For Android-related operations, the NativeScript CLI will use a built-in version of adb.
To avoid possible issues with the native Android emulator, Genymotion or connected
Android devices, verify that you have installed the latest Android SDK and
its dependencies as described in http://developer.android.com/sdk/index.html#Requirements 

✖ WARNING: The Android SDK is not installed or is not configured properly. 
 You will not be able to run your apps in the native emulator. To be able to run apps
in the native Android emulator, verify that you have installed the latest Android SDK 
and its dependencies as described in http://developer.android.com/sdk/index.html#Requirements 

✖ Cannot find a compatible Android SDK for compilation. To be able to build for Android, install Android SDK 28 or later. 
 Run `$ sdkmanager` to manage your Android SDK versions. 

✖ You need to have the Android SDK Build-tools installed on your system. You can install any version in the following range: '>=23 <=30'. 
 Run `$ sdkmanager` from your command-line to install required `Android Build Tools`. In case you already have them installed, make sure `ANDROID_HOME` environment variable is set correctly. 

Your environment is not configured properly and you will not be able to execute local builds.
Verify that your environment is configured according to the system requirements described at
https://docs.nativescript.org/environment-setup.html#macos-android.
zeddrix@Zeddrixs-MacBook-Pro todoapp % 

我试着卸载Android studio,然后重新安装它,因为我想这可能是原因,但还是没有。我没有用Xcode做这个,因为下载它需要很长时间,而且这个关于ANDROID的错误似乎与Xcode没有联系。

export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/platform-tools

共有1个答案

孟翰藻
2023-03-14

经过几天的等待和研究,我已经阅读了Android Studio关于设置env var的官方文档。看到了:

(ANDROID_SDK_ROOT)设置SDK安装目录的路径。一旦设置,该值通常不会改变,并且可以由同一台机器上的多个用户共享。不推荐使用ANDROID_HOME,它也指向SDK安装目录。如果继续使用它,以下规则适用:如果定义了ANDROID_HOME并包含有效的SDK安装,则使用它的值而不是Android_SDK_ROOT中的值。如果未定义ANDROID_HOME,则使用ANDROID_SDK_ROOT中的值。如果定义了ANDROID_HOME,但不存在或不包含有效的SDK安装,则使用ANDROID_SDK_ROOT中的值。

我知道我可以为Android_Home这样做。但是由于文档中说它是不推荐的,所以我决定在ANDROID_SDK_ROOT上执行此操作。我打开终端机,运行如下:

set ANDROID_SDK_ROOT=Users\zeddrix\Library\Android\sdk\
export ANDROID_SDK_ROOT=/Users/zeddrix/Library/Android/sdk
set ANDROID_HOME=Users\zeddrix\Library\Android\sdk\
export ANDROID_HOME=/Users/zeddrix/Library/Android/sdk
You need to have the Android SDK Build-tools installed on your system. You can install any version in the following range: '>=23 <=30'. 
 Run `$ sdkmanager` from your command-line to install required `Android Build Tools`. In case you already have them installed, make sure `ANDROID_HOME` environment variable is set correctly.
 类似资料:
  • 我是使用Salesforce SDK开发本机应用程序的新手。我尝试使用ForceRoid工具从命令行创建android项目,但是在设置环境变量AndroidHome时遇到了问题。 但我不知道如何设置这个变量。 我附上截图来正确描述我的问题。

  • 我在“React-Native Run-Android”上得到以下错误..怎么修? 在https://help.gradle.org获得更多帮助 在1s中生成失败,无法在设备上安装应用程序,请阅读上面的错误以了解详细信息。确保运行了Android模拟器或连接了设备,并设置了Android开发环境:https://facebook.github.io/react-native/docs/geting

  • 我在使用appium运行java mobile automation测试用例时遇到了这个错误 处理命令时发生未知的服务器端错误。原始错误:packageAndLaunchActivityFromManifest失败。原始错误:找不到aapt请用Android SDK根目录路径设置ANDROID_HOME环境变量。(警告:服务器未提供任何stacktrace信息) 配置: IntelliJ IDE-

  • 在为基本GET服务运行Java集成测试时,我们的应用程序代码无法检索环境变量。然而,当我们运行应用程序本身时,它可以毫无问题地检索变量。 我们正在开发一个Mac(el captiain)与intellij作为我们的IDE。我们已经导出了bash_profile中的变量(例如导出ORACLE_URL="*************").我们可以在设置和刷新后对变量进行回声。 我们完全搞不懂为什么它们在

  • 问题内容: 我在运行show时有一个file.sh:未设置TERM环境变量。 问题答案: 您可以看到它是否真的没有 设置 。运行命令。 如果没有,则可以这样设置: