Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Android Studio with WSL (bash) as your shell Terminal?

Is it possible to use Android Studio and configure Windows Subsystem for Linux as a Terminal? I really don't like to work with Windows cmd.exe, but when I try to switch to bash.exe, which seems to work, it cannot build the project because there are missing e.g. Android/sdk/build-tools/27.0.3/aidl'.

This file is there, but it is with .exe suffix as it was downloaded for Windows. Any workaround to use *unix like bash for Terminal in Android Studio while being on Windows 10?

like image 585
Jakub Gruber Avatar asked Apr 05 '18 17:04

Jakub Gruber


People also ask

How do I run terminal on WSL?

To start using WSL, open up a PowerShell terminal and type wsl . If you've set up WSL correctly, you'll enter a bash terminal running on the WSL distro of choice. From here, you can run any Linux commands you wish.

How do I use Bash in WSL?

Install WSL Install Windows Subsystem for Linux with the command, wsl --install. Use a Bash terminal on your Windows machine run by your preferred Linux distribution - Ubuntu, Debian, SUSE, Kali, Fedora, Pengwin, Alpine, and more are available.

Does WSL support Bash?

Once you've configured your system to run WSL (i.e., Bash on Ubuntu on Windows), access it by clicking the Bash on Ubuntu on Windows icon (Figure 1), which will launch you into a Bash console (Figure 2). The remainder of this article will show some of the interesting things you can do using the WSL.

How do I open Android Studio in terminal?

To launch Android Studio, open a terminal, navigate to the android-studio/bin/ directory, and execute studio.sh . Select whether you want to import previous Android Studio settings or not, then click OK.


2 Answers

Yes, it is possible. I'm doing it right now. I have an Ubuntu app as WSL and figured out that it's accessible at C:\Windows\System32\bash.exe

So, open Android Studio and navigate to File -> Settings -> Tools -> Terminal. There fill Shell paht with C:\Windows\System32\bash.exe and voilà!

Now, when you open a new terminal it will use the WSL you have installed in your machine.

I'm using Android Studio 4.0.1.

like image 170
Plinio.Santos Avatar answered Oct 25 '22 22:10

Plinio.Santos


I'm setting this up right now and hit your question from Google looking for advice. So with that caveat, let me explain what I did to get it running and if you have follow up questions we may need to experiment together to find the answers.

First, I installed VcXserv: https://sourceforge.net/projects/vcxsrv/. This X Server for windows allows you to run graphical linux applications in WSL. You'll just need to export the display variable in your ~/.bashrc since that isn't done normally in WSL:

$ echo "export DISPLAY=:0" >> ~/.bashrc

Then you have to run XLaunch from the start menu. It takes you through the config dialogs (just choose the defaults) and it puts an icon in the notification area you can check to make sure it's running.

Then, you want to download the Linux version of Android Studio 3.1. Extract it into the WSL filesystem somewhere (I used ~/apps). Then from your bash shell you can run android-studio/bin/studio.sh and the window will appear and begin the unboxing dialogs.

This is as far as I've gotten, right now it's downloading the SDK. I still am not sure how adb over usb is going to work or tested the emulator. I'll update this if I learn more.


Update unfortunately, VcXserv is crashing when the main Android Studio window launches. I'm going to file a bug report on it and try some other X servers if I have time later.

like image 1
Segfault Avatar answered Oct 25 '22 20:10

Segfault