Получение "переменная среды ANDROID_HOME не установлена" при запуске "ns run" и "ns doctor android"

Я использую MacOS. Я уже использовал Android Studio и Xcode в одном из моих проектов, ориентированных на реакцию. Сейчас изучаю SvelteNative. Поскольку я начал следить за документами здесь и здесь и перешел на шаг, где мне нужно запустить 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, а затем установить ее снова, потому что я думал, что это может быть причиной, но все равно ничего. Я не делал этого с Xcode, потому что его загрузка занимает очень много времени, и поскольку эта ошибка с ANDROID, похоже, не связана с Xcode.

Затем я искал решение проблемы с отсутствующей или неуместной переменной окружения ANDROID_HOME. Эта статья мне помогла.

Итак, я побежал:

cd ~/

touch .bash_profile

open -e .bash_profile

А затем поместите их в .bash_profile:

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

Но все еще ничего ... Я тоже не знаю, как устранить следующие предупреждения ниже этого. Помощь.

1 ответ

Решение

После нескольких дней ожидания и исследований я прочитал официальную документацию Android Studio по настройке переменных env . И увидел, что:

(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

Ошибка об этом ANDROID_HOME исчезла. Теперь мне нужно было решить только одну ошибку:

      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.

Мне помог первый комментарий в этом вопросе . Я пошел в SDK Manager моей Android Studio> SDK Tools, а затем, как сказал @Kevin McCarpenter:

«Снимите флажок (на самом деле отметьте)« Показать сведения о пакете », а затем вы можете выбрать более низкую версию. Если вы не собираете для Android 12 (и, вероятно, еще не), вы можете снять флажок« 31 .0.0 »и поставить отметку 30.0.3 '. После этого перейдите в build.gradle в своем приложении и измените buildToolsVersion '31.0.0' на buildToolsVersion '30.0.3'"

Затем я запустил ns run android (как я сказал, когда я запустил ns run --help), и, наконец, это сработало!

Другие вопросы по тегам