After creating a NativeScript Typescript application, I tried running it using the command "ns run android" it doesnt run and i get the output - android-studio

After creating a NativeScript Typescript application, I tried running it using the command ns run android I get this output and does not run.
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.
No compatible version of the Android SDK Build-tools are installed on your system. You can install any version in the following range: '>=23 <=32'.
Install the required build-tools through Android Studio. In case you already have them installed, make sure the ANDROID_HOME environment variable is set correctly.

Your errors and warnings says that you haven't Android SDK and adb which one is included in the Android SDK Platform-Tools package.
First of all, you need to read this doc and complete steps in it - https://docs.nativescript.org/environment-setup.html. This documentation has everything you need, based on your operating system and the operating system you want to develop the application for.
If you already install everything docs says, check your path environment for ANDROID_HOME and adb variables presence, if not, add them. For example, my path (on MacOS) contains following lines:
/Users/sixhellstations/Library/Android/sdk/emulator:/Users/sixhellstations/Library/Android/sdk/tools:/Users/sixhellstations/Library/Android/sdk/tools/bin:/Users/sixhellstations/Library/Android/sdk/platform-tools

Related

Getting "ANDROID_HOME environment variable is not set" when running "ns run" & "ns doctor android"

I'm using MacOS. I've already used Android Studio and Xcode to one of my react-native projects before. I am now learning SvelteNative. As I've started following the docs here and here, and got onto the step where I need to run ns doctor android I get this error:
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 %
I get this too when running 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 %
I tried uninstalling Android studio and then installing it again because I was thinking it could be the cause but still nothing. I didn't do this with Xcode because it takes very long to get it downloaded and since this error about ANDROID doesn't seem to have a connection about Xcode.
Then I searched for solving the issue about the missing or misplaced ANDROID_HOME environment variable. This article helped me.
So I ran:
cd ~/
touch .bash_profile
open -e .bash_profile
And then put these in .bash_profile:
export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/platform-tools
But still got nothing... I don't know how to solve the next warnings below this, too. Help.
After days of waiting and researching, I've read the official Android Studio docs for setting env vars. And saw that:
(ANDROID_SDK_ROOT) Sets the path to the SDK installation directory. Once set, the value
does not typically change, and can be shared by multiple users on the
same machine. ANDROID_HOME, which also points to the SDK installation
directory, is deprecated. If you continue to use it, the following
rules apply: If ANDROID_HOME is defined and contains a valid SDK
installation, its value is used instead of the value in
ANDROID_SDK_ROOT. If ANDROID_HOME is not defined, the value in
ANDROID_SDK_ROOT is used. 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.
I know that I can do this for ANDROID_HOME. But since the docs says here that it's deprecated, I've decided to do this on the ANDROID_SDK_ROOT instead. I opened up my Terminal and ran this:
set ANDROID_SDK_ROOT=Users\zeddrix\Library\Android\sdk\
It seemed like the CLI is waiting for another command after I did this so I then did this:
export ANDROID_SDK_ROOT=/Users/zeddrix/Library/Android/sdk
If that doesn't work, try this:
set ANDROID_HOME=Users\zeddrix\Library\Android\sdk\
Then:
export ANDROID_HOME=/Users/zeddrix/Library/Android/sdk
The error about this ANDROID_HOME has gone. Now I only had one error left to solve:
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.
The first comment in this question helped me through. I went to SDK Manager of my Android Studio > SDK Tools and then as #Kevin McCarpenter said:
"Uncheck (check actually) 'Show Package Details' and then you can select
a lower version. If you're not building for android 12 (and you
probably aren't yet), you can uncheck '31.0.0' and check '30.0.3'.
After that, go into the build.gradle in your app and change
buildToolsVersion '31.0.0' to buildToolsVersion '30.0.3'"
Then I ran ns run android (as said when I run ns run --help) and it finally worked!

Android studio is giving the following error when I am trying to build a ionic project "Gradle sync failed: Sync failed: reason unknown"

I am trying to build a ionic project in Android studio on Ubuntu 20.04 . I am using the command ionic capacitor build then android studio opens up as expected then it shows this error Gradle sync failed: Sync failed: reason unknown. I am unable find a solution for this particular gradle sync error. I have reinstalled Ubuntu and other things but still the problem persists.
In my case, a fresh install of Android Studio resulted in Android 31 being the only SDK available but the project was targeting Android 30. I went to Tools > SDK Manager and made sure the appropriate version of Android SDK was installed and available. After restarting, and allowing the gradle sync to complete I was able to build/run the app on a virtual device, etc.
Here is what I found
This is the screenshot thanks for helping.
Capacitor lets you manage your own Android project. Like any IDE-backed project, sometimes things get so out of sync that the only solution is to rebuild the project.
To do this, follow these steps:
Copy any source code you created (such as Java files in app/android/src, manifest files, or resource files) into a safe location outside of app/android.
Next, make sure you are running an updated version of the Capacitor CLI:
npm install #capacitor/cli#latest
Remove the android directory:
rm -rf android/
Re-create the Android app from Capacitor:
npx cap add android
Copy your saved source files back into the project.
Check the error log. You should find something like "Module: 'mobile' platform 'android-30' not found" or something similar. Click Tools > SDK Manager and download the appropriate Android SDK Platform package.
on top right you will see option to view log file upon clicking there you will redirect to file manager and open idea file there
example :
open idea file and scroll down you will see actual issue.
In my case android sdk 31 was not installed.
I installed android sdk 31 from File>Settings>Apprearance and behaviour>system settings>android sdk and install required android sdk and rebuild the project.
accord to my observation in most cases you get this error because you have not required sdk installed in your system.

Is Gradle included in Android Studio?

I run cordova requirements on an Android app created with cordova and are getting this error:
Gradle: not installed
Could not find an installed version of Gradle either in Android Studio,
or on your system to install the gradle wrapper. Please include gradle
in your path, or install Android Studio
First I would like to say that yes, I can install it manually, but why if it should be included?
So what is the issue here? Is it a lie that it should be sufficient to install Android Studio as the error message says? Do I need to install it manually also? Or do I simply need to set a path?
Gradle is probably included in Android Studio. At least, some of its tooling APIs must be included to provide Gradle interop.
However, Android Studion has nothing to deal with the command line commands you're running in console, like cordova requirements. You should probably install it and make available globally. SDKMAN! is a good tool to manage tools in Java world.

Android emulator for nativescript don't work

I don't know why my Nativescript App don't launch on my android emulator..
More explanation :
I'm on Manjaro (Linux).
I have install android studio and setup environment variable like :
JAVA_HOME=/usr/lib/jvm/default
ANDROID_SDK_ROOT=$HOME/Android/Sdk
ANDROID_HOME=$HOME/Android/Sdk
ANDROID_AVD_HOME=$HOME/.android/avd
NPM=$HOME/.npm-global/bin
COMPOSER=$HOME/.config/composer/vendor/bin
export PATH=$PATH:$NPM:$COMPOSER::$ANDROID_SDK_ROOT:$ANDROID_HOME:$ANDROID_AVD_HOME:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools:$JAVA_HOME
After launch my device in emulator of android studio when I make "tns run android --emulator"
this append :
✖ 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
✖ Cannot find a compatible Android SDK for compilation. To be able to build for Android, install Android SDK 28.
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 <=28'.
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.
✖ Error executing command 'javac'. Make sure you have installed The Java Development Kit (JDK) and set JAVA_HOME environment variable.
You will not be able to build your projects for Android.
To be able to build for Android, verify that you have installed The Java Development Kit (JDK) and configured it according to system requirements as
described in http://docs.nativescript.org/setup/ns-cli-setup/ns-setup-linux.html#system-requirements
✖ WARNING: The Java Development Kit (JDK) is not installed or is not configured properly.
I don't know why..

Android Studio SDK manager doesn't show the candidate packages(How to install CMake)

From the post "Add C and C++ Code to Your Project",
You can install these components using the SDK Manager:
From an open project, select Tools > Android > SDK Manager
from the menu bar. Click the SDK Tools tab. Check the boxes next to LLDB,
CMake, and NDK, as shown in figure 1.
there is a image shows
But my Android Studio is not like that.
I upload a image to show my Android Studio sdk manager settings:
I googled for a while, but I didn't find anything useful. My PC is win10 64bit, I run Android Stdio 64bit, version is 2.2, I use the Android Studio bunndle version(I assume the AS and the sdk are one thing).
I also run Android Studio 2.3 on another PC, I check the sdk manager on version 2.3, it looks like behaving the same. I also try to run AS in the administrator role. it looks like behaving the same too.
The different on the AS2.2 and AS2.3 is that I can run the sdkmanager command in a win shell to install the CMake/LLDB on the PC that has AS 2.3, but I can't find the sdkmanager command in the SDK folder which is associated with the AS 2.2, so I go to download a standlone command line tools from the developer.android.com, I unzip the downloaded file and get a fold named "tool", what should I do? shold I merge the downloaded tool folder into the android_sdk/tools?
The below image is the sdk settings on another PC that has installed the AS 2.3. I installed the CMake the LLDB from the command line: "sdkmanager.bat cmake;3.6.4111459"
Why my Android Studio doesn't show the candidate not
installed packages?
Shold I merge the downloaded command line tool folder into the android_sdk/tools?

Resources