microsoft / vscode-cordova

A Visual Studio Code extension providing intellisense, debug, and build support for Cordova and Ionic projects.
https://marketplace.visualstudio.com/items?itemName=vsmobile.cordova-tools
Other
293 stars 68 forks source link

Enviroment paths are not taken into account. #590

Closed Hadatko closed 4 years ago

Hadatko commented 4 years ago

Actual Behavior

  1. In Visual Studio Code terminal i see correct enviroment paths for Android SDK 2.In Visual Studio Code debug i see wrong default enviroments paths for Android SDK -> cause build tools not found error

Expected Behavior

  1. Take enviroment variables from system

Software versions

Outputs (Include if relevant)

Configure project :app Project evaluation failed including an error in afterEvaluate {}. Run with --stacktrace for details of the afterEvaluate {} error.

FAILURE: Build failed with an exception.

BUILD FAILED in 0s Command finished with error code 1: /home/kuhadatko/kseftiky/daq-ozm/daq-ozm/gui/android/platforms/android/gradlew cdvBuildDebug,-b,/home/kuhadatko/kseftiky/daq-ozm/daq-ozm/gui/android/platforms/android/build.gradle /home/kuhadatko/kseftiky/daq-ozm/daq-ozm/gui/android/platforms/android/gradlew: Command failed with exit code 1 Error output: Project evaluation failed including an error in afterEvaluate {}. Run with --stacktrace for details of the afterEvaluate {} error.

FAILURE: Build failed with an exception.

BUILD FAILED in 0s Error: /home/kuhadatko/kseftiky/daq-ozm/daq-ozm/gui/android/platforms/android/gradlew: Command failed with exit code 1 Error output: Project evaluation failed including an error in afterEvaluate {}. Run with --stacktrace for details of the afterEvaluate {} error.

FAILURE: Build failed with an exception.

BUILD FAILED in 0s at ChildProcess.whenDone (/home/kuhadatko/kseftiky/daq-ozm/daq-ozm/gui/android/node_modules/cordova-common/src/superspawn.js:135:23) at ChildProcess.emit (events.js:193:13) at maybeClose (internal/child_process.js:999:16) at Process.ChildProcess._handle.onexit (internal/child_process.js:266:5) 'cordova run android --device --verbose --no-update-notifier' failed with exit code 1

- Visual Studio Code Terminal Output:

kuhadatko@kuhadatko-GL552VW:~/kseftiky/daq-ozm/daq-ozm/gui/android$ echo ${ANDROID_SDK_ROOT} /home/kuhadatko/Android/Sdk kuhadatko@kuhadatko-GL552VW:~/kseftiky/daq-ozm/daq-ozm/gui/android$ echo ${ANDROID_HOME} /home/kuhadatko/Android/Sdk

RedMickey commented 4 years ago

Hi @Hadatko and thanks for your reporting. As seen from your logs there may be two different ANDROID_HOME system variable definitions in ~/.bashrc and ~/.bash_profile. VS Code editor launched from UI requires system variables to be defined in ~/.bash_profile. Please make sure that your ~/.bash_profile file contains correct environment variables.

Hadatko commented 4 years ago

Hi @RedMickey, unfortunatelly i don't have .bash_profile at all.

Hadatko commented 4 years ago

It looks like newer OS doesn't have .bash_profile file. Are you parsing this file? Is it wise? Shouldn't you read system environment variables from system itself?

e.g.: If you can run shell command, you can run this: printenv

RedMickey commented 4 years ago

@Hadatko, the extension doesn't parse any environment variables itself. It uses the environment variables that VS Code editor provides to it. If there isn't ~/.bash_profile file in your system, please make sure that ~/.profile file refers to ~/.bashrc and ~/.bashrc contains all the environment settings.

~/.profile should contain something like this to forward all settings from ~/.bashrc :

if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
        . "$HOME/.bashrc"
    fi
fi

Please add the code above to ~/.profile file if there isn't.

  1. Run nano ~/.profile
  2. Add the code above and save the changes
  3. Run source ~/.profile
  4. Restart VS Code editor

Also you can start VS Code from system terminal by using code command. So the editor will take variables from ~/.bashrc file.

Could you please try these suggestions and let us know about your results?

Hadatko commented 4 years ago

I am always running code from cmd. But i need to tell that today it is working. Maybe restart system helped (i don't know how. I restarted app several times with new terminal with actual enviroment as described above.). I also don't have .profile file. But it started work so i am fine. Thank you for your time and help ;)

RedMickey commented 4 years ago

Sounds good! Please feel free to open new ones if needed.

Windstalker commented 4 years ago

@RedMickey I am using zsh isntead of bash and I have the same issue. What should I do in my case?

RedMickey commented 4 years ago

Hi @Windstalker, I tried to use zsh instead of bash and didn't face any problems. I configured zsh the following way:

  1. Download zsh and set it as default
  2. Add NVM configuration to ~/.zshrc
    export NVM_DIR="$HOME/.nvm"
    [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
    [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
  3. Run source ~/.zshrc in terminal

After that VS Code should also use zsh as default terminal.