- Setting it up
- Download the image to your PinePhone
- Append contrib to the default SourcesList
- Update and install the requisite packages
- Copy the Android image
- Create a new service file
- Edit the anbox-container-manager.service unit file
- Change the anbox-session-manager.service unit file
- Reload the service files
- Try it
- Other distributions
I had tried Anbox before, way back when it was really popular (around ~2017). It also is really easy to install on postmarketOS, where it is a
sudo apk add postmarketos-anbox away, and I had failed to build it from the AUR (Danct12 has pounced on the issue since). Therefore I followed two posts on the pine64.org forums, which explain the process of installing Anbox on Mobian step by step. It’s not easy, but at least to me, it seems that it runs faster on Mobian than it does on postmarketOS.
Setting it up
The following is a bland copy of the instructions on the Pine64 forum, with a handful changes, along to the Mobian Gitlab issue. Therefore all credit goes to nas, jed, and Djhg2000.
Download the image to your PinePhone
Append contrib to the default SourcesList
printf '%s' ' contrib' | sudo tee -a /etc/apt/sources.list
This did not work for me. Just open
/etc/apt/sources.list in Vim or an editor of your choice as root and type a space and contrib after the word main, so that it looks like this afterwards:
deb http://deb.debian.org/debian bullseye main contrib
Update and install the requisite packages
sudo apt update && sudo apt -y install anbox adb
Copy the Android image
sudo mv android-7.1.2_r39-anbox_arm64-userdebug.img /var/lib/anbox/android.img
Create a new service file
Using your favourite editor, create the file
[Unit] Description=binderfs [Mount] What=binder Where=/dev/binderfs Type=binder [Install] WantedBy=anbox-container-manager.service
Edit the anbox-container-manager.service unit file
This fix originates from Mobian Issue #63.
Change the file
/lib/systemd/system/anbox-container-manager.service (lines 4, 6, 10, 11) so that it has the following content:
[Unit] Description=Anbox Container Manager Documentation=man:anbox(1) After=network.target dev-binderfs.mount Wants=network.target Requires=dev-binderfs.mount ConditionPathExists=/var/lib/anbox/android.img [Service] #ExecStartPre=/sbin/modprobe ashmem_linux #ExecStartPre=/sbin/modprobe binder_linux ExecStartPre=/usr/share/anbox/anbox-bridge.sh start ExecStart=/usr/bin/anbox container-manager --daemon --privileged --data-path=/var/lib/anbox ExecStopPost=/usr/share/anbox/anbox-bridge.sh stop [Install] WantedBy=multi-user.target
Change the anbox-session-manager.service unit file
Change the file
/lib/systemd/user/anbox-session-manager.service so that it has the following content:
[Unit] Description=Anbox Session Manager Documentation=man:anbox(1) After=graphical.target Wants=graphical.target [Service] ExecStart=/usr/bin/anbox session-manager [Install] WantedBy=default.target
Reload the service files
sudo systemctl daemon-reload
sudo systemctl restart anbox-container-manager.service
systemctl --user daemon-reload
systemctl --user restart anbox-session-manager.service
Anbox is now installed. Anbox must be open to allow installation of APKs via adb, so start it.
anbox launch --package=org.anbox.appmgr --component=org.anbox.appmgr.AppViewActivity
A good first app to install is FDroid, the open-source Android store:
and install it:
adb install F-Droid.apk
Android applications can be launched from the Phosh launcher (as .desktop files), or from the Anbox Application Manager.
Not enough RAM
The 2GB RAM of the PinePhone are not that much, and Anbox is quite the RAM eater. Therefore, I use ZRAM with a really shitty script called
.zram.sh, which has to be run as root:
modprobe zram echo 3.5G > /sys/block/zram0/disksize mkswap --label zram0 /dev/zram0 swapon --priority 100 /dev/zram0
I really should do this via systemd, but did not get around to it yet.
While Anbox should work fine now even after reboots (as long as it has enough RAM), the network connection has to be set up manually every time, after a crash or a reboot:
sudo /usr/share/anbox/anbox-shell.sh su ip route add default dev eth0 via 192.168.250.1 ip rule add pref 32766 table main ip rule add pref 32767 table local
I already tried to simplify this step via
adb, but after
adb root adb does not find the Anbox emulator anymore.
EDIT, 22:50h CEST: Djhg2000 added their findings to a long standing issue at the Anbox project.
As shown in my video, the Phosh keyboard, Squeekboard, does not work with Android. Apparently, this is a known bug with other SDL2 and Xwayland apps, too. My temporary fix was to just install and enable (you will need to do so in the Android settings) an Android software keyboard. I tried multiple and had the best results with Simple Keyboard, which has an option to scale it’s height — I settled on 125 %. Now, don’t think that this is a perfect solution — it most definitely is not, as you can’t see the keyboard, it shows as a black or white (and thus on a white background sometimes invisible) rectangle. You will not see the keys, you will need to guess their positions! But hey, it is working for text input. Another work around is, apparently according to the issue linked above, a hardware keyboard, e.g. a Bluetooth one. One more reason I can’t wait for the Pine64 hardware keyboard for PinePhone!
Apps look blurry - they apparently don’t if you set Phosh to 1x scaling. That however comes with an entirely different set of issues, e.g. a miniscule virtual keyboard, which you would than have to adjust. I think I could deal with the blurryness, but it would be great to see that issue fixed. Secondarily, apps always scale to the full height of the device. This in unfortunate, as Phosh has bars with UI elements on the top and bottom of the screen which then obscure your Android apps. I haven’t seen anything on how to even attempt fixing this problem, and will update this post if I do.
Obviously, Anbox can only be a stop-gap solution to be used when there is no native or web-based alternative. Many of these apps may not work. One problem is that currently Android 7.1.2 (Nougat) is the most advanced release working with Anbox. Meanwhile, Google is working to get Android 11 ready. And: With the default image, you don’t have any of Googles Play services, that many proprietary apps require (in case you are wondering, the Aurora Store app can tell you, whether a certain app you desire requires these services). MicroG, an open-source reimplementation of some of the Play Services, apparently works with Anbox. Also, there are images for amd64-PCs with included Play Services [available in the Arch User Repository], but I don’t know whether these still work — and assuiming they do work, Google could stop this any day.
The current state of Anbox can be summarized with ‘it sort of works’. Unfortunately, the 2GBs of RAM the PinePhone ships with, are a limiting factor here, and everybody who pre-ordered the Convergence Package can be extra happy, as that extra Gigabyte of RAM will come in handy here, too. While a few bugs that affect the operation of Anbox are likely to be fixed within a couple of weeks, others may take way longer or forever. Luckily, there are other options to ‘running’ Android apps on the PinePhone, and I look forward to investigate and writing about these soon.
Added on August 16th, 2020:
While the above describes how I did enable Anbox on Mobian, the instructions should apply to other distributions that use systemd, too. You will need to obtain an Anbox package though, which might be tough.
Getting Anbox to work should be particularily easy on ArchLinux ARM/Huong Tram Linux, as Danct12 packaged Anbox for it. So become root,
pacman -S anbox, download the Android image, move it to
/var/lib/anbox/android.img (you can now do that via
pacman -S anbox-image, too) and
systemctl enable --now anbox-container-manager and it should work.
Added on August 21st, 2020: Manjaro now offers an image with Anbox (including the Android image) preinstalled for download.