Running Jetpack Compose on Windows 10

Alex Vainshtein
3 min readJun 30, 2019

--

I was excited when the new UI toolkit was introduced at Google IO 2019, and i wanted to try it straight away. But to my disappointment, it still in an early-exploration, pre-alpha stage, and there is no library that i can simply add to my project to test it.

Following the documentation on Jetpack Compose i learned, that to try it i need to set up the toolchain for AndroidX development, and check out the source code of android.x. But to my disappointment, Google allowing it only on Linux or Mac OS (but not on Windows).

So i started to search, how can i still do it on Windows 10. After a lot of attempts i was finally able to get the source code and run Jetpack Compose on Windows 10.

The Steps

  1. Install Windows Subsystem for Linux
  • Open PowerShell as Administrator.
  • Run: “Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux”.
  • Restart your computer when prompted.

2. Install Ubuntu

  • Open the Microsoft Store and find Ubuntu.
  • Install Ubuntu.
  • Launch Ubuntu and follow the instructions.

3. Checking out the code

  • Install repo
mkdir ~/bin
PATH=~/bin:$PATH
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
  • Configure Git with your real name and email address.
git config — global user.name “Your Name”
git config — global user.email “you@example.com”
  • Create a directory for your checkout (it can be any name)
mkdir androidx-master-dev
cd androidx-master-dev
  • Use repo command to initialize the repository.
repo init -u https://android.googlesource.com/platform/manifest -b androidx-master-dev
  • Now your repository is set to pull only what you need for building and running AndroidX libraries. Download the code (and grab a coffee while we pull down 6GB):
repo sync -j8 -c

You will use this command to sync your checkout in the future — it’s similar to git fetch.

4. Install VcXsrv Windows X Server

To run graphical Linux applications on Bash on Ubuntu on Windows 10 we need to install VcXsrv

  • After installation launch XLaunch, follow the instructions(keep the defaults).
  • To start the required version of Android Studio, you need to run the studiow command from the /ui subfolder
cd path/to/checkout/frameworks/support/ui/
./studiow

Now Android Studio should be running, and you can start playing with Jetpack Compose (try running ui-demos module).

Note: If you encountered this error: Startup Error: Unable to detect graphics environment
Try to run this command:
export DISPLAY=:0.0

Note: Because we are running Android Studio inside VcXsrv Windows X Server, the Android Studio will be running slower.

If you have trouble running emulator from this version of Android Studio, try to launch emulator from your regular Android Studio, and the run the application on it.

Example Application Running on Emulator on Windows 10:

Links:

Jetpack Compose: https://android.googlesource.com/platform/frameworks/support/+/refs/heads/androidx-master-dev/ui/README.md

Android Jetpack:
https://android.googlesource.com/platform/frameworks/support/+/androidx-master-dev/README.md

Windows Subsystem for Linux Installation Guide for Windows 10:
https://docs.microsoft.com/en-us/windows/wsl/install-win10

Ubuntu App Installation:
https://tutorials.ubuntu.com/tutorial/tutorial-ubuntu-on-windows#0

VcXsrv Windows X Server:
https://sourceforge.net/projects/vcxsrv/

--

--