avdmanager: Command failed with exit code 1 cordova
Asked Answered
N

8

16

i just started to make my first native cordova app from cordova official tutorial, and when I run

ayam@laptop:~/Documents/learn/hello$ cordova requirements

Requirements check results for android:

Java JDK: installed 1.8.0
Android SDK: installed true
Android target: not installed 
*** avdmanager: Command failed with exit code 1
Gradle: installed /usr/local/gradle-3.5/bin/gradle
Error: Some of requirements check failed

I got avdmanager: Command failed with exit code 1

Nazar answered 13/7, 2017 at 14:39 Comment(3)
@Neitzen ID Android home is not set properlyLibertylibia
@Libertylibia ` ayam@laptop:~/Documents/learn/hello$ echo $ANDROID_HOME /home/ayam/Android/Sdk ayam@laptop:~/Documents/learn/hello$ cd /home/ayam/Android/Sdk ayam@laptop:~/Android/Sdk$ ls build-tools extras ndk-bundle platforms sources emulator licenses patcher platform-tools tools `Nazar
did you created an AVD using AVD manager first?Libertylibia
A
23

This problem has possibly 3 origins:

  1. Android tools path settings
  2. JAVA installation
  3. JAVA_HOME path settings

I have explained how to solve all of these on macOS below (Windows might be slightly different)

1. Android tools might not be added with the correct path:

I solved it by doing this in macOS terminal:

PATH=$PATH:$HOME/Library/Android/Sdk/emulator
PATH=$PATH:$HOME/Library/Android/Sdk/tools
PATH=$PATH:$HOME/Library/Android/Sdk/tools/bin
PATH=$PATH:$HOME/Library/Android/Sdk/platform-tools
export ANDROID_HOME=$HOME/Library/Android/

These are all the required path variables by Cordova.

Important:
Make sure that there is a folder called /Android/ inside your user folder inside Library!

It used to be installed directly to the user folder instead of in Library so therefor the confusion.

2. JAVA might be missing or the wrong version:

You need to use JAVA SE v 1.8 for Cordova to work.
Do this in the terminal:

/usr/libexec/java_home -V

and check if that version is available or not. If not you can research how to install it in there with homebrew. Then try the above command again to double check it installed properly.

3. JAVA_HOME path might not be set up properly

Do this in the terminal:

echo $JAVA_HOME

If you see nothing that means your $JAVA_HOME variable is not exported properly. You can solve this by doing this in the terminal:

export JAVA_HOME=`/usr/libexec/java_home -v 1.8`

That's all!

Agamogenesis answered 1/1, 2019 at 10:49 Comment(3)
@Samuel Liew♦ You were right. I have deleted my answer from the least relevant post and want to keep only the answer on this question. Since it is most relevant. However, I could not undelete my other answer, so had to post again. Thank you for your understanding. Best regards.Agamogenesis
I am running JDK 11 and the correct command for setting JAVA_HOME for me was export JAVA_HOME="/usr/libexec/java_home -v 11"Hooch
In my case, Cordova didn't want to use Java version 18 or 11 either, so only after pointing to Java version Java 1.8 it worked like a charm.Mori
F
4

This problem arises when there is no virtual device set up in the system (No target version or no target device). I am not sure if that is a must. You can add a device using SDK manager.

In SDK manager, Add an android repository (For example - Android 5.0.1 API 21) and all dependencies like SDK Tools etc.

Then try cordova requirements. If you are able to run an instance of emulator then this error will go off..(It worked for me that way!)

Hope this helps..

Fleisher answered 13/7, 2017 at 15:44 Comment(2)
can you be more specific on how to do this? "In SDK manager, Add an android repository (For example - Android 5.0.1 API 21) and all dependencies like SDK Tools etc."Agamogenesis
Use sdkmanager command like tool. Example command for adding a platform - sdkmanager "platform-tools" "platforms;android-28" for API level 28(latest till date). More info - developer.android.com/studio/command-line/sdkmanagerFleisher
N
4

I've found the sollution for this issue was to install cmdline-tools from AndroidStudio's SDK Manager and then add it to PATH like: export PATH=$PATH:$ANDROID_HOME/cmdline-tools/latest/bin

Northeastwards answered 28/10, 2022 at 10:22 Comment(1)
Thank you from the future. In my case I also needed to completely unset ANDROID_HOME and use ANDROID_SDK_ROOT instead, or Cordova gave me a "Failed to find" environment variable message and complained about not being able to find the tools folder.Keegan
J
2

If you are ready this in 2019 here is what you need to for this problem, earlier that would have been a path variables issues regardless of what OS it is. While we are dealing with Open JDK 11+ just for being pretty advanced or updated to latest releases.

Step 1: Remove all available JavaVirtualMachines Step 2: Check whether your system is Java free (No Java JVM or JRE) Step 3: Install Java 8 JDK ( As Cordova is supported by Java 1.8 and corresponding JREs) Step 4: Install Android Targets using sdkmanager command. Step 5: Install whatever you need from requirements and set their path in mac using bash profile or temporary paths. Or you may need to set it again and again.

You are good to go, Sorry I could not share the commands over here as they are already available in Google. No Offence! I knew you were close fixing this, but I hope even this helps you understanding Cordova requirements.

Joacimah answered 10/7, 2019 at 9:1 Comment(0)
S
1

To make changes permanent on your system and the variable keep working after close the terminal, ou after a restart use:

nano ~/.bash_profile 

Add lines:

export ANDROID_HOME=/YOUR_PATH_TO/android-sdk
export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
export PATH=$PATH:$ANDROID_HOME/platform-tools
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/emulator

To make it available immediately run

source ~/.bash_profile

Reopen terminal and check if it worked:

echo $ANDROID_HOME
echo $JAVA_HOME
Sleight answered 10/6, 2020 at 19:10 Comment(0)
O
1

I know this is a late answer, but this issue happened to me last week, and I couldn't figure it out after following the different suggestions here. I applied the other things that mesqueeb's explains in their answer:

  • Added the routes in the PATH
  • Verified that Java was there and the version was valid
  • Checked that Java was linked correctly in JAVA_HOME

The problem was that I had two different versions of the Android SDK, and the system was picking the commands from the obsolete version. I had installed it a long time back for testing and completely forgot about it.

The error happened when executing avdmanager, so I ran the which command to see where it was picking the executable:

which avdmanager

And there, I saw it was picking the command from usr/local/bin instead of from the directory where I had installed the latest Android SDK. usr/local/bin was imported into the path before the new Android SDK, so a temporary solution was to replace the order of the PATH: instead of appending the new Android SDK paths at the end of the PATH, I prepended them to the beginning:

PATH=$HOME/Library/Android/Sdk/emulator:$PATH
PATH=$HOME/Library/Android/Sdk/tools:$PATH
PATH=$HOME/Library/Android/Sdk/tools/bin:$PATH
PATH=$HOME/Library/Android/Sdk/platform-tools:$PATH
export ANDROID_HOME=$HOME/Library/Android/

That solved the problem. Ultimately, I ended up uninstalling the old version (I didn't need it anymore). I had used Brew cask to install it, so I ran the following command:

brew uninstall --cask android-sdk

(Notice that if you have a similar issue, the uninstalling process will depend on how you installed the Android SDK. In my case, it was brew, but you may have used a different method.)

Overword answered 19/9, 2023 at 19:23 Comment(0)
E
0

In Android Studio, you can use cmd + ; for Mac or Ctrl + Alt + Shift + S for Windows/Linux to pull up the Project Structure dialog. In there, you can set the JDK location as well as the Android SDK location.

Add this to your .bashrc or .zshrc config so that the JAVA_HOME variable points to the Java version used by Android.

Elegance answered 22/8, 2019 at 10:16 Comment(0)
S
0

Additionally, this problem can occur if you run the app without an emulator or Android device.

Symploce answered 16/12, 2021 at 10:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.