How to test Android apps in Emulator/Device via WSL (Windows Subsystem Linux)

Hello, I have been trying for over a week now to figure out how to test Ionic Android apps through WSL (Windows Subsystem Linux). I use WSL for my development environment (Ubuntu version 16.04) with Windows 10, and it has worked great for everything so far except for trying to develop Native Ionic apps and test in Android.

I have installed Android Studio/SDK, Java, and Gradle on both Windows and the Linux Subsystem (as well as installed & configured proper Android environments using sdkmanager), and have tried a combination of using both environments to build and emulate Android apps. Since WSL can launch native Windows executables such as.exe files, in theory I believe this should be possible to do completely via WSL.

However, the only successful method I have found so far is to install the android-sdk in Linux, build the .apk file via ionic cordova build android, and then manually open the emulator on Windows and drag and drop the created .apk file to the emulator to install and run the build. This is quite cumbersome, but so far has been the only method I have found that works.

If I set up my environment to be completely based on the Linux environment, running ionic cordova requirements works successfully and returns the following:

Requirements check results for android:
Java JDK: installed 1.8.0
Android SDK: installed true
Android target: installed android-28,android-27
Gradle: installed /opt/gradle/gradle-5.1.1/bin/gradle

I am also successfully able to build a .apk file. The problem is that I cannot seem to use the emulator, because WSL has no GUI, and I need to be able to use the emulator based in Windows.

If I set up my environment based on Windows (noting that I still need the Java run time environment based in Linux), everything else appears to work but I receive the following error when running ionic cordova build android or ionic emulate android:

Execution failed for task ':CordovaLib:compileDebugAidl'. 
> java.lang.IllegalStateException: aidl is missing

Running ionic cordova requirements with that configuration gives me the following output:

Requirements check results for android:
Java JDK: installed 1.8.0
Android SDK: installed true
Android target: not installed
android: Command failed with exit code ENOENT
Gradle: installed /mnt/c/Program Files/Android/Android Studio/gradle/gradle-4.10.1/bin/gradle

For some reason, with my Windows configuration it does not recognize the Android target (even though it is properly installed), which leads to the ':CordovaLib:compileDebugAidl' error.

Does anybody have any advice on how to test Ionic Android apps with the emulator while using WSL? Thank you!!

1 Like

Any solution?
Iā€™m looking for a way to use windows on a new computer or keep running linux as default.

1 Like

I gave up on the emulator but was able to get adb connected to my physical device via tcpip thanks to this how-to.

The relevant bits:

You must have android studio installed for both windows and your wsl distro.

  1. Make sure the phone is connected to same wifi as your PC
  2. Connect phone to PC via USB
  3. windows cmd line, run adb devices and make sure your device is connected, permission given on device, etc
  4. windows cmd line, run adb tcpip 5555
  5. wsl bash, run adb connect <your phone's IP address>
1 Like