惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
人人都是产品经理
人人都是产品经理
IT之家
IT之家
T
The Blog of Author Tim Ferriss
V
V2EX
博客园 - 聂微东
The Cloudflare Blog
Blog — PlanetScale
Blog — PlanetScale
A
About on SuperTechFans
U
Unit 42
Vercel News
Vercel News
L
LangChain Blog
博客园 - 司徒正美
H
Help Net Security
Recent Announcements
Recent Announcements
Recorded Future
Recorded Future
V
Visual Studio Blog
Jina AI
Jina AI
Microsoft Azure Blog
Microsoft Azure Blog
GbyAI
GbyAI
Y
Y Combinator Blog
C
Check Point Blog
博客园 - 三生石上(FineUI控件)
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
J
Java Code Geeks
The Register - Security
The Register - Security
The GitHub Blog
The GitHub Blog
B
Blog RSS Feed
F
Fortinet All Blogs
B
Blog
G
Google Developers Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
云风的 BLOG
云风的 BLOG
爱范儿
爱范儿
MongoDB | Blog
MongoDB | Blog
F
Full Disclosure
有赞技术团队
有赞技术团队
罗磊的独立博客
博客园_首页
MyScale Blog
MyScale Blog
aimingoo的专栏
aimingoo的专栏
Google DeepMind News
Google DeepMind News
M
MIT News - Artificial intelligence
N
Netflix TechBlog - Medium
Engineering at Meta
Engineering at Meta
量子位
I
InfoQ
小众软件
小众软件
P
Proofpoint News Feed

Feed of liolok

Fix Broken URLs of My Site Containerize Steam with systemd-nspawn Run Desktop App with systemd-nspawn Container Oculus Quest 2 Usage Note Set Environment Variables with pam_env Install Arch Linux on Acer Swift 3 SF313-52 Run Mastodon Server on Arch Linux VPS V2Ray Subscription Parse Manage Dotfiles with Git and Stow Run SS and MTProxy Server on AWS How to Add Image to Hexo Blog Post Build Blog with Hexo and GitHub Pages
Containerize Android Studio with systemd-nspawn
2021-07-07 · via Feed of liolok

cd ~{,/zhs/}

Create Btrfs Subvolume

# su # switch to root user
# cd /var/lib/machines
# container_name=android-studio
# btrfs subvolume create $container_name

Then it will be easy to snapshot and migrate the container.

Install Minimal Ubuntu

Reference: systemd-nspawn - ArchWiki

Codename of current latest LTS version of Ubuntu is focal.

# codename=focal
# repository_url='https://mirrors.bfsu.edu.cn/ubuntu/'
# debootstrap --include=systemd-container \
--components=main,universe $codename $container_name $repository_url

After installation, run systemd-nspawn --machine=$container_name to boot into brand new container.

Network

You may need to add --bind-ro=/etc/resolv.conf option to make DNS work in container.

To check network status, consider commands ping 1.1.1.1 and ping archlinux.org: if former works and latter doesn’t, it would be DNS problem.

32-bit Libraries

Inside container, enable i386 architecture and install the libraries.

# dpkg --add-architecture i386
# apt-get update
# apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386 lib32z1 libbz2-1.0:i386

Android Studio

You could either curl/wget the latest version package inside container, or download it on host and mount it to container:

# host_as_archive='/data/Downloads/android-studio-ide-202.7486908-linux.tar.gz'
# systemd-nspawn --machine=$container_name --bind-ro=$host_as_archive:/tmp/as.tar.gz

Inside container, add a dedicated normal user named “android” and extract Android Studio to user home:

# useradd --create-home android
# su - android
# tar --extract --verbose --file=/tmp/as.tar.gz
# mv android-studio studio

After this, Android Studio is installed under /home/android/studio/, run /home/android/studio/bin/studio.sh to start up:

# user=android
# startup_script='/home/android/studio/bin/studio.sh'
# systemd-nspawn --machine=$container_name --user=$user $startup_script

Oh no, this won’t work because I forget to mention Xorg stuff. Command options become just too many, from this step we need start to actually write up a shell script to run Android Studio in GUI.

Fix Dependency

TL;DR: Run apt-get install libxext6 libxrender1 libxtst6 libxi6 libfreetype6 fontconfig to start up.

This log complains about missing library file libXext.so.6, so let’s try a “reverse query”:

# systemd-nspawn --machine=$container_name --bind-ro=/etc/resolv.conf
# apt-get install apt-file
# apt-file update
# apt-file search libXext.so.6

It turned out the package name should be libxext6. After installing it, another four same errors came along, so all the missing libraries would be:

apt-get install libxext6 libxrender1 libxtst6 libxi6 libfreetype6

Android Studio finally starts up… but crashes right away. The log mentions “font” a lot, so I tried installing fontconfig package then it finally starts up.

Fix Cursor Theme

Mount host icon theme to container and set environment variable:

# host_data=/usr/share
# data=/home/$user/.local/share
# systemd-nspawn --machine=$container_name \
--bind-ro=$host_data/icons:$data/icons --setenv=XCURSOR_PATH=$data/icons

Install X cursor management library in container:

# systemd-nspawn --machine=$container_name --bind-ro=/etc/resolv.conf apt-get install libxcursor1

Wrap Up

I wrote a fish-shell script, and a desktop entry according to AUR.