Score:3

Can WSL2 use the Android SDK installed on Windows?

bi flag

I have the android-sdk installed on Windows, and I have exported its path to the ANDROID_SDK_ROOT WSL environment variable. Should WSL be able to compile my projects using the SDK that's installed on Windows? It says my SDK is corrupted when I try to build my Cordova project. Could this be the cause? I've uninstalled/reinstalled the same version of the SDK and a few other, but the problem remains.

Score:1
vn flag

While Ubuntu on WSL can execute most any Windows binary, keep in mind that Windows binaries still won't understand Linux paths, processes, environment variables, and some other configuration items/files that Ubuntu provides. For this reason, I typically recommend that you run Windows programming tools such as the Android SDK from Windows. If you want to use the Linux version of the Android SDK, you can do that from Ubuntu under WSL.

For instance, you mention that you exported ANDROID_SDK_ROOT, but a Windows process started from inside Ubuntu/WSL will not see that Linux environment variable.

You can fix this by using the WSLENV variable feature of WSL (original devblog announcement with more detail).

That means, for the Windows version of the Android SDK to see ANDROID_SDK_ROOT, you need to add that variable name to the WSLENV variable.

For example:

export ANDROID_SDK_ROOT='C:\path\to\SDK\`
export WSLENV="$WSLENV:ANDROID_SDK_ROOT`

While this might solve part of the problem, note that you must use the Windows path format above instead of the WSL/Linux path (/mnt/c/path/...). This is because you are running a Windows process.

These issues could in theory all be worked around with things like wslpath, WSLENV, and other features, but again, for tools like this, I typically would recommend:

  • Using the Windows version of the toolchain (editor, commandline, SDK, tools, etc.)
  • Or using all-Linux versions of the toolchain.

Mix and match only in (a) simple cases, or (b) if you know how to troubleshoot and solve any issues that come up.

Nivlem avatar
bi flag
Thank you for the explanation, it makes things clearer !
Score:0
kg flag

WSL can run Windows programs but they will be run as normal Windows processes. I'm not familiar with the program that you are trying to run, but be aware that it is equivalent to running it on Windows.

You can ensure your interoperability works by calling notepad.exe from Linux and seeing notepad start. If this works, then your problem is specific to the application you're running.

Compiling in one OS with another OS's tools seems unlikely to work, I'm not familiar enough with Android's SDK to comment any further.

Nivlem avatar
bi flag
I will use a vm instead of this weird setup, then. Thank you !
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.