Running Capacitor apps from WSL on Windows Android Studio

Wondering if anyone has been able to run Capacitor apps on the WSL filesystem on the Windows version of Android Studio?

I think Android Studio has recently added WSL support, but whenever I try to Gradle Sync I get this:

14:38	Gradle sync started
14:38	Gradle sync failed: Operation result has not been received. (16 s 409 ms)

There is no further explanation so it’s difficult to debug.

WSL is a bit finicky at the moment due to how the Capacitor/Ionic CLIs and WSL are implemented. Could you go into more details with your setup?

Sure!

My app is on my Ubuntu Filesystem at /home/user/my-app/. I can open Android Studio on Windows and select my WSL project just fine, Android Studio will also tell me it’s loading from WSL (I think IntelliJ has recently added support for it).

Unfortunately The sync process just fails. After some googling I found this issue on the Jetbrains tracker, people seem to be saying it’s an issue with the Android Plugin but I don’t actually know if the issue is the same.

Android Studio info:

Android Studio Bumblebee | 2021.1.1 Patch 2
Build #AI-211.7628.21.2111.8193401, built on February 17, 2022
Runtime version: 11.0.11+9-b60-7590822 amd64
VM: OpenJDK 64-Bit Server VM by Oracle Corporation
Windows 10 10.0
GC: G1 Young Generation, G1 Old Generation
Memory: 1280M
Cores: 8
Registry: external.system.auto.import.disabled=true
Non-Bundled Plugins: org.jetbrains.kotlin (211-1.6.20-release-275-AS7442.40)

The npx cap sync or the “Sync Gradle” button in Android Studio? Maybe while we do better to support WSL you could do npx cap copy android and then use the “sync gradle” button in Android Studio if that works?

I’m talking about the Sync Gradle in Android studio. npx cap sync and npx cap copy both work fine as they’re just copying/generating files to the filesystem.

Tried running npx cap copy and then hitting the “Sync Project with Gradle files” button:

image

It fails like mentioned before.

Does your WSL instance have $JAVA_HOME set? I wonder if it’s set in Windows but not available in WSL for some reason?

Funnily enough it isn’t set in either environment, however that shouldn’t make a difference afaik?

I can run:

./gradlew assembleDebug

From terminal and it will work as long as I have ANDROID_SDK_ROOT set up.

Either way I tried setting the variable:

echo $JAVA_HOME
/mnt/c/Program Files/Java/jdk-18

Then running Gradle Sync again, but the result was the same:

09:28	Gradle sync started

09:29	Gradle sync failed: Operation result has not been received. (12 s 941 ms)

Settings show me it’s using this JDK for gradle operations, which looks correct to me :man_shrugging:

EDIT:

I also tried setting to a WSL location:

echo $JAVA_HOME
/home/leonardo/.jdks/openjdk-18

Same result