Thank you very much to our former student, Xiao Zhou Peiqi, for the submission. The issue of coexisting Windows and Ubuntu systems is something many developers need, as there are not many who work purely on Ubuntu like Ma Ge. Therefore, our student has analyzed an article on setting up a Windows + WSL environment.
Comparison of Several Development Environment Solutions
When developing Android Framework, we inevitably need to use the Linux system, with Ubuntu being the most widely used. However, for various reasons, we still need to use Windows to handle some other tasks, leading to the following environment setup solutions:
-
1. Ubuntu + Windows Dual Boot
This solution has the best cost and performance experience, requiring only one machine with no performance loss during compilation. The downside is that switching systems requires shutting down the Windows system, and if the machine is performing a time-consuming task (usually compilation), you have to wait for it to finish or interrupt it.
-
1. Windows Physical Machine + Ubuntu Virtual Machine
This solution has the same cost as the first but incurs performance loss during compilation. However, it resolves the disadvantage of the first solution, allowing you to use software from both systems without shutting down.
-
1. **Windows Physical Machine + Ubuntu Physical Machine**
This solution is slightly more costly as it requires purchasing two machines, one running Windows and the other running Ubuntu, with file sharing implemented via SMB. Additionally, for convenience in development, based on my personal experience, the following two types of dual-machine environments can be set up:
1. **Single Monitor or Monitor Only Connected to Windows**
This solution can utilize MSRDP (Microsoft Remote Desktop Protocol) to operate the Ubuntu GUI. It is recommended to use version 24.04 for better support of remote desktop, but some software in the compilation environment needs to be compiled and installed.
2. **Both Machines Connected to Monitors**
Using this solution, you can use Synergy
software to share keyboard and mouse, and clipboard (only supports text and images, not files), achieving the effect of controlling two machines with one set of keyboard and mouse.
-
1. Windows Physical Machine + WSL Subsystem
This solution is similar to the second one, as it is also a virtual machine solution, but with Microsoft’s system-level support (requires a newer system version), it incurs less performance loss and does not require tools for remote access, as a GUI can be launched simply by executing commands, providing an experience close to native.
Setting Up the WSL Environment
This article’s focus is not on configuring the basic WSL environment but rather on setting up the Android Framework compilation environment. Therefore, I won’t go into too much detail about installing WSL; if needed, please search for it yourself. I referred to this blog for guidance, which you can check here: https://www.cnblogs.com/stlong/p/17654389.html
Additionally, it is necessary to check articles related to running GUI applications in WSL on Microsoft’s website: https://learn.microsoft.com/en-us/windows/wsl/tutorials/gui-apps. The system version must be Windows 10 version 19044+ or Windows 11 to run Linux GUI applications. Please pay attention to this issue if you need to use ASFP for Framework development.
Installing the WSL Subsystem
Enabling WSL
Before installing the WSL system image, we need to go to Control Panel
– Programs
– Programs and Features
– Turn Windows features on or off
and enable the Windows Subsystem for Linux
option and Virtual Machine Platform
. If not enabled, you need to click OK and restart.
Installing the System Image
After enabling WSL, you can search for the corresponding image in the Microsoft Store for installation. I installed version 20.04, which does not require any additional steps for dependency installation and has good compatibility; it is recommended to install this version.
After installation, click to open to proceed with the image installation.
Follow the prompts to set the username and password.
Moving the System Path
Typically, the system path for images installed via Microsoft Store is stored on the C drive, and since most people’s computers have multiple drives, the C drive’s capacity is relatively small. Downloading code and compiling will lead to the system drive being full, so we need to move the installation location to another drive, based on your needs. If compiling a high-version code, it is recommended to store it in a partition with at least 300G of free space.
-
1. Close WSL
wsl --shutdown
-
1. Check the WSL image name
wsl -l
From the command result, the previously installed image name is Ubuntu-20.04
. After obtaining the name, proceed to the next step.
-
1. Export the WSL image package
-
1. Create a corresponding folder at the path where you want to export; if it already exists, skip this step. I created a WSL_Backup folder on the E drive.
-
2. Export the image package.
wsl --export Ubuntu-20.04 E:\WSL_Backup\Ubuntu20.04.tar
3. Once exported, you will see an image file at the corresponding path.
-
1. Unregister the original image
wsl --unregister Ubuntu-20.04
-
1. Import the exported image to the migration path
-
1. Create a corresponding folder at the path where you want to install.
-
2. Import the image.
wsl --import Android E:\AndroidWSL E:\WSL_Backup\Ubuntu20.04.tar
After installation, check in E:\AndroidWSL to see a virtual hard disk file.
System Environment Configuration
Building the Compilation Environment
For the system environment setup, WSL is consistent with Ubuntu physical machines or VMware virtual machines, and you can follow the normal steps. However, it is important to note that the code path can only be placed in ext4 hard disk partitions or WSL-created virtual hard disk partitions. It is recommended to pull the code directly in the virtual hard disk partition (but ensure that the installed partition has enough space), as mounting physical hard disks to WSL is relatively complicated.
As for the compilation environment, I followed the steps from another blog of mine to compile. You can refer to Ma Ge’s blog on environment setup.
About Virtual Machines
Since the AOSP’s built-in virtual machine relies on KVM, and WSL does not support KVM, I found online that you can create a virtual machine through Android Studio and then start your compiled system.img by specifying command line parameters. However, I did not succeed in my attempts; students in need can refer to this blog: https://www.cnblogs.com/stlong/p/17654389.html
WSL Accessing the Physical Machine
This part is quite tricky. Initially, I wanted to share the physical machine’s USB devices with WSL, but after trying, I found that using the adb devices command to get the device list would hang indefinitely. Later, I discovered that WSL and Windows can access the same version of adb, allowing WSL to access the physical machine’s adb devices. If access fails, you need to execute a command in adb to start the adb service program. Personally, I prefer to use adb devices directly.
Download link for adb:
-
• linux: https://dl.google.com/android/repository/platform-tools-latest-linux.zip
-
• windows:https://dl.google.com/android/repository/platform-tools-latest-windows.zip[1]
It is recommended that the WSL on the physical machine be configured with system environment variables after downloading via the link, rather than using the Android SDK path. Otherwise, if updated through other tools, this issue may arise again, and forgetting about it could lead to significant problems.
Installing Chrome
Since we need to download Android Studio for Platform
, but Google has a check on its web side that prevents downloading from non-Linux devices, I attempted to modify the browser UA but to no avail. If anyone has related success experiences, please share. Therefore, we need to download a browser on WSL. I personally prefer Chrome, but you can download other browsers as you like.
Download the installation package
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
Installation
sudo apt install --fix-missing ./google-chrome-stable_current_amd64.deb
Installing Android Studio for Platform
First, we open Chrome through <font style="color:rgb(22, 22, 22);background-color:rgb(230, 230, 230);">google-chrome</font>
.
Then download from the following URL:
https://developer.android.google.cn/studio/platform
Note not to change the language to Chinese, as I found that changing the language to Chinese made the download button ineffective; switch to English to download.
Installation
cd ~/Downloads
sudo apkg -i asfp-xxx-linux.deb
Launch
/opt/android-studio-for-platform/bin/studio.sh
For the usage of ASFP, please search for related articles on Baidu; there are many excellent articles, and this article will not elaborate on this.
Conclusion
Problem Solving
WslRegisterDistribution failed with error: 0x80370114
Reference: https://zhuanlan.zhihu.com/p/599286889
-
1. Start WSL, this step is actually the same as in section 2.1.1 and can be ignored.
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
-
1. Enable virtual machine features; this step can be checked via the GUI interface in section 2.1.1 for the Virtual Machine Platform option, check it to enable.
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
-
1. Set WSL version to WSL2
wsl --set-default-version 2
Five, References
https://zhuanlan.zhihu.com/p/599286889
https://www.cnblogs.com/stlong/p/17654389.html
https://learn.microsoft.com/en-us/windows/wsl/tutorials/gui-apps
Cited Links
[1]
https://dl.google.com/android/repository/platform-tools-latest-windows.zip: https://dl.google.com/android/repository/platform-tools-latest-linux.zip
More technical courses on framework learning:
For specific purchasing methods, you can contact Ma Ge via WeChat:
Leave a Comment
Your email address will not be published. Required fields are marked *