Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not find environment variables #17

Closed
alanpduque opened this issue Nov 16, 2017 · 9 comments
Closed

Can not find environment variables #17

alanpduque opened this issue Nov 16, 2017 · 9 comments

Comments

@alanpduque
Copy link

When I click on the "Debug Android" button, the console gives an error saying "SDK location not found", but when I run "react-native run-android" via command line it works perfectly.
Seems like the plugin is not able to find the ANDROID_HOME environment variable set on my OS(elementary OS 0.4.1 Loki).

image

@beansoft
Copy link
Owner

Seems your OS is really new. And please try this solution, add a android local config file:
yourapp/android/local.properties
sdk.dir=/Users/xxxx/Documents/Java/android-sdk-macosx
let sdk.dir point to your ANDROID_HOME environment

@beansoft
Copy link
Owner

Since i've not tested the plugin under Linux, so I'll do a research on what happened.

@alanpduque
Copy link
Author

alanpduque commented Nov 17, 2017

Thanks for the quick reply,
The local.properties file worked for the sdk, but now it can't find the adb, probably the same problem happens with the $PATH environment variable, where the adb path is defined.
FYI, I tried creating a run configuration(with another intellij plugin) executing a sh file with the "run-android" command and the same problem happened.
Maybe it is something in the way things inside plugins are instanciated.

@spitoglou
Copy link

@alanpduque Hi, I had the same issue and I found a solution by creating a link of the adb executable in a directory that the OS has access by default. In my case (Ubuntu 16.04), I did:
sudo ln -s /Android/Sdk/platform-tools/adb /bin/adb
After this, the plugin finds adb without any problem.

Hope that helps...

@beansoft
Copy link
Owner

beansoft commented Nov 20, 2017

I've do a test on an centos desktop, however the virtualbox linux is a bit outdated and i can't setup a full node.js env on it.
Here is my ~/.bash_profile content:

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
	. ~/.bashrc
fi

# User specific environment and startup programs

export JAVA_HOME=/soft/WebStorm-172.4343.25/jre
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin

export PATH

then I brings up a modified plugin on webstorm, and it reads path env correctly. Also i've copyed a java executable and rename it to adb, and webstorm finds it well.

And how webstorm or idea read the system env variable? it's a bit fun: it calls python -i $WEB_STORM_HOME/bin/printenv.py then got the output there.

So if anyone could help me with:

  1. edit your ~/.bash_profile file like this to add adb to PATH env:
    export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home
    export ANDROID_HOME=/Users/beansoft/Documents/Java/android-sdk-macosx
    export PATH=${PATH}:${ANDROID_HOME}/tools:${ANDROID_HOME}/platform-tools

  2. check whether you can execute python in your terminal.

And send me the final result here.

And still i'm trying to setup an complete Linux env to do a real test.

virtualbox_oracle linux_20_11_2017_14_04_12

@beansoft
Copy link
Owner

beansoft commented Nov 20, 2017

I've found the reason, by default, most people config envs following the office react native guild will edit your bashrc like this:

PATH="~/Android/Sdk/tools:~/Android/Sdk/platform-tools:${PATH}"
export PATH

that's why adb can't be found, since IDEA plugin system doesn't parse ~/ as absolute path at all, so it can't found the adb command. To resolve this problem, it's really simple, replace ~ with an absolute path in your bashrc or bash_profile file, like this:

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

And for Elementary/Ubuntu users, double click on the launch shell, eg: bin/webstorm.sh, seems doesn't load the bashrc settings at all, so please make sure start it throw a terminal: open a terminal first, then start the IDE by typing ./webstorm.sh.

I've tested this on Elementary, now all commands executes fine.

@beansoft
Copy link
Owner

And seems @spitoglou 's solution is the most simple one step:

sudo ln -s ~/Android/Sdk/platform-tools/adb /usr/bin/adb

IDEA's bug can't be fixed by me, so i'd like to let u do a test and close this bug.

@alanpduque
Copy link
Author

I tried openning intellij trough console and it really worked fine.
Since I don't want to do that every time, I will use @spitoglou approach to the problem, which worked perfectly too.
Thank you all very much for the help!

@asozcan
Copy link

asozcan commented May 8, 2018

echo "export PATH=\$PATH:/Users/${USER}/Library/Android/sdk/platform-tools/" >> ~/.bash_profile
above works too but you need to do a restart for linux/macos

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants