Skip to content
Advertisement

Cordova can’t find $ANDROID_HOME

I found a lot of solutions but they didn’t help me.

I defined variables in /home/username/.zshrc

export ANDROID_HOME="/home/username/Android/Sdk"
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools

And variables were defined because:

echo $ANDROID_HOME                -> /home/username/Android/Sdk
echo $ANDROID_HOME/tools          -> /home/zemil/Android/Sdk/tools
echo $ANDROID_HOME/platform-tools -> /home/zemil/Android/Sdk/platform-tools

Also command below works fine:

> ionic cordova requirements

Requirements check results for android:
Java JDK: installed 1.8.0
Android SDK: installed true
Android target: installed android-29,android-28
Gradle: installed /usr/share/java/gradle/bin/gradle

I try to build a project

> sudo ionic cordova build --release android --verbose

...
Prepared android project successfully
No scripts found for hook "after_prepare".
No scripts found for hook "before_compile".
CordovaError: Failed to find 'ANDROID_HOME' environment variable. Try setting it manually.
Detected 'adb' command at /usr/bin but no 'platform-tools' directory found near.
Try reinstall Android SDK or update your PATH to include valid path to SDK/platform-tools directory.

Advertisement

Answer

In tried many files with env variable for my linux

In manjaro linux it needs to write env variables only in file:

/etc/environment

export ANDROID_HOME="/home/{USER_NAME}/Android/Sdk"
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools

So cordova works well in this case

Change USER_NAME to your linux user name

Also should refresh paths ($ source ./environment) or restart system

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement