How-to install anbox from sources on Mint 20 without snap

Write tutorials for Linux Mint here
More tutorials on https://github.com/orgs/linuxmint/discu ... /tutorials and (archive) on https://community.linuxmint.com/tutorial
Forum rules
Don't add support questions to tutorials; start your own topic in the appropriate sub-forum instead. Before you post read forum rules
Post Reply
GNULinux

How-to install anbox from sources on Mint 20 without snap

Post by GNULinux »

COURTESY: mr.Kallys(from linux mint -community)
ORIGINAL SOURCE: https://community.linuxmint.com/tutorial/view/2501


i guess it would help you it worked in my case :D

tutorial starts here entire tutorial is inside quotes :

I. Introduction
The main purpose of this tutorial is to share my experience of building and running Anbox project from sources in Ulaya.

Anbox is a container-based approach to boot a full Android system on a regular GNU/Linux system.
Anbox is only officially deployed on the snap app store, and since snap store is disabled by default on linux Mint 20, this tutorial will try to help you to compile and run Anbox directly from sources. There is also a quite old version (2019-11-15) in apt.

Personnally, I am absolutely not an expert in compilation and I failed several times in past to build anbox, mainly due to a lack of documentation and some obscure black magic. I hope this tutorial will give you keys to make it working but I can’t guarantee you that this will work on your system.

1. Tested environment
Source: master#170f1e0
Mint: 20 (Ulaya)
Kernel: 5.4.0-48-generic
C/CXX Compiler : GNU 9.3.0
I recommend you to configure your system to get as close as possible to this environment.

2. Useful resources
Anbox user guide
Anbox readme
Debian Anbox package source
II. Building anbox
1. Prerequisites
a) Kernel modules
As explained in official documentation, you need to load two kernel modules : ashmem_linux and binder_linux.

$ sudo modprobe ashmem_linux
$ sudo modprobe binder_linux
$ ls -1 /dev/{ashmem,binder}
/dev/ashmem
/dev/binder
If you experience issue with binder_linux, try this instructions. (Thanks to RogerWilco)

b) Dependencies
$ sudo apt update
$ sudo apt install build-essential cmake cmake-data debhelper dbus google-mock \
libboost-dev libboost-filesystem-dev libboost-log-dev libboost-iostreams-dev \
libboost-program-options-dev libboost-system-dev libboost-test-dev \
libboost-thread-dev libcap-dev libexpat1-dev libsystemd-dev libegl1-mesa-dev \
libgles2-mesa-dev libglm-dev libgtest-dev liblxc1 \
libproperties-cpp-dev libprotobuf-dev libsdl2-dev libsdl2-image-dev lxc-dev \
pkg-config protobuf-compiler libgmock-dev git
2. Compilation
1. Go where you want to build (assuming here "/usr/local/src/" directory)

$ cd /usr/local/src
2. Get sources

$ sudo git clone https://github.com/anbox/anbox.git --recurse-submodules
3. Adjust permissions and create a build directory

$ sudo chown -R $USER:$USER anbox/
$ mkdir anbox/build/
$ cd anbox/build/
4. Prepare for compilation

$ cmake ..
-- The C compiler identification is GNU 9.3.0
-- The CXX compiler identification is GNU 9.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- No build type selected, default to RelWithDebInfo
-- Treat warnings as errors
-- Found Boost: /usr/lib/x86_64-linux-gnu/cmake/Boost-1.71.0/BoostConfig.cmake (found version "1.71.0") found components: filesystem log serialization system thread program_options
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.1")
-- Found Threads: TRUE
-- Found EGL: /usr/lib/x86_64-linux-gnu/libEGL.so
-- Found GLESv2: /usr/lib/x86_64-linux-gnu/libGLESv2.so
-- Found Protobuf: /usr/lib/x86_64-linux-gnu/libprotobuf.so;-lpthread (found version "3.6.1")
-- Checking for module 'sdl2'
-- Found sdl2, version 2.0.10
-- Checking for module 'SDL2_image'
-- Found SDL2_image, version 2.0.5
-- Checking for module 'dbus-1'
-- Found dbus-1, version 1.12.16
-- Checking for module 'lxc'
-- Found lxc, version 4.0.2
-- Checking for module 'properties-cpp'
-- Found properties-cpp, version 0.0.1
-- Checking for module 'libsystemd'
-- Found libsystemd, version 245
-- Checking for module 'libcap'
-- Found libcap, version 2.32
-- LXC version: 4.0.2
-- Checking for module 'gtest'
-- Found gtest, version 1.10.0
-- Checking for module 'gtest_main'
-- Found gtest_main, version 1.10.0
-- Checking for module 'gmock'
-- Found gmock, version 1.10.0
-- Checking for module 'gmock_main'
-- Found gmock_main, version 1.10.0
-- Found Boost: /usr/lib/x86_64-linux-gnu/cmake/Boost-1.71.0/BoostConfig.cmake (found version "1.71.0") found components: iostreams system
-- Found Boost: /usr/lib/x86_64-linux-gnu/cmake/Boost-1.71.0/BoostConfig.cmake (found version "1.71.0") found components: filesystem system unit_test_framework
-- Found libdw: /usr/lib/x86_64-linux-gnu/libdw.so
-- Found libbfd: /usr/lib/x86_64-linux-gnu/libbfd.so
-- Found libdwarf: /usr/lib/x86_64-linux-gnu/libdwarf.so
-- Found Backward: /usr/local/src/anbox/external/backward-cpp
-- Looking for dlfcn.h
-- Looking for dlfcn.h - found
-- Looking for getauxval
-- Looking for getauxval - found
-- Configuring done
-- Generating done
-- Build files have been written to: /usr/local/src/anbox/build
At this step, triple check everything is alright. If something went wrong here, you must fix it before continuing.

5. Cross fingers and compile!

$ make
[...]
Scanning dependencies of target buffer_queue_tests
[100%] Building CXX object tests/anbox/graphics/CMakeFiles/buffer_queue_tests.dir/buffer_queue_tests.cpp.o
[100%] Linking CXX executable buffer_queue_tests
[100%] Built target buffer_queue_tests
Scanning dependencies of target lxc_container_tests
[100%] Building CXX object tests/anbox/container/CMakeFiles/lxc_container_tests.dir/lxc_container_tests.cpp.o
[100%] Linking CXX executable lxc_container_tests
[100%] Built target lxc_container_tests
You surely will see some warnings, but you should not see any errors.

6. Install anbox For some reasons, “sudo make install” failed with insufficient permissions, so I went with “sudo -i”.

$ sudo -i
$ cd /usr/local/src/anbox/build/
$ make install
[ 3%] Built target sdbus-cpp
[ 10%] Built target process-cpp
[ 12%] Built target emugen
[ 13%] Built target OpenglCodecCommon
[ 14%] Built target renderControl_dec
[ 17%] Built target GLESv2_dec
[ 19%] Built target GLESv1_dec
[ 25%] Built target emugl_common
[ 27%] Built target OpenGLESDispatch
[ 28%] Built target xdg
[ 29%] Built target xdg_test
[ 29%] Built target backward
[ 30%] Built target backward_object
[ 31%] Built target utils
[ 32%] Built target cpu_features
[ 34%] Built target list_cpu_features
[ 35%] Built target unix_based_hardware_detection
[ 38%] Built target anbox-protobuf
[ 88%] Built target anbox-core
[ 89%] Built target anbox
[ 90%] Built target intent_tests
[ 91%] Built target restricted_manager_tests
[ 92%] Built target at_parser_tests
[ 93%] Built target scope_ptr_tests
[ 93%] Built target binary_writer_tests
[ 94%] Built target type_traits_tests
[ 94%] Built target small_vector_tests
[ 95%] Built target message_channel_tests
[ 96%] Built target render_control_tests
[ 97%] Built target layer_composer_tests
[ 98%] Built target buffered_io_stream_tests
[100%] Built target buffer_queue_tests
[100%] Built target lxc_container_tests
Install the project...
-- Install configuration: "RelWithDebInfo"
-- Installing: /usr/local/share/anbox/ui/loading-screen.png
-- Installing: /usr/local/include/backward.hpp
-- Installing: /usr/local/lib/backward/BackwardConfig.cmake
-- Installing: /usr/local/lib/libcpu_features.a
-- Installing: /usr/local/include/cpu_features/cpu_features_macros.h
-- Installing: /usr/local/include/cpu_features/cpu_features_cache_info.h
-- Installing: /usr/local/include/cpu_features/cpuinfo_x86.h
-- Installing: /usr/local/bin/list_cpu_features
-- Installing: /usr/local/lib/cmake/CpuFeatures/CpuFeaturesTargets.cmake
-- Installing: /usr/local/lib/cmake/CpuFeatures/CpuFeaturesTargets-relwithdebinfo.cmake
-- Installing: /usr/local/lib/cmake/CpuFeatures/CpuFeaturesConfig.cmake
-- Installing: /usr/local/lib/cmake/CpuFeatures/CpuFeaturesConfigVersion.cmake
-- Installing: /usr/local/bin/anbox
-- Set runtime path of "/usr/local/bin/anbox" to ""
$ exit
7. Test

$ anbox
NAME:
anbox - anbox

USAGE:
anbox [command options] [arguments...]

COMMANDS:
check-features Check that the host system supports all necessary features
wait-ready Wait until the Android system has successfully booted
system-info Print various information about the system we're running on
launch Launch an Activity by sending an intent
session-manager Run the the anbox session manager
version Print the version of the daemon
help Print a short help message
8. If you reach this step, you have successfully compiled Anbox! Congrats!

9. Additional checks : especially check that binder and ashmem are recognised.

$ anbox check-features
Your computer does meet all requirements to run Anbox
$ anbox system-info
version: local-170f1e0
cpu:
arch: x86
brand: Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
features:
- aes
- sse4_1
- sse4_2
- avx
- avx2
os:
name: Linux Mint
version: 20 (Ulyana)
snap-based: false
kernel:
version: Linux version 5.4.0-48-generic (buildd@lcy01-amd64-010) (gcc version 9.3.0 (Ubuntu 9.3.0-10ubuntu2)) #52-Ubuntu SMP Thu Sep 10 10:58:49 UTC 2020
binder: true
ashmem: true
graphics:
[...]
III. Running Anbox
1. Introduction
As doc says, Anbox does not contain any android image and uses :

a container manager
a session manager
What doc does not say is what to do with those info when you know nothing about the project and virtualization.

Hopefully, sources of debian package of anbox took me to the right way:

Session manager depends on Container manager to run
Container manager depends on anbox-bridge.sh script and the famous android image to run
anbox-bridge.sh appears to be on a scripts/ directory inside anbox sources ("/usr/local/src/anbox/scripts/")
android image is… to build or find on the Internet
2. Get an android image
This operation must be done once, but you need an android image to run container manager. You can download one from here, altought images are not really recent.

Alternatively you can build your own android image as explained here, but I have not tested it and this is not covered by this tutorial (maybe another one?).

1. Download image

$ wget https://build.anbox.io/android-images/2 ... _amd64.img
2. Check integrity

$ wget https://build.anbox.io/android-images/2 ... .sha256sum
$ sha256sum -c android_amd64.img.sha256sum
3. Create a directory for storing this image, let’s say "/var/lib/anbox"

$ sudo mkdir /var/lib/anbox
4. Move the android image to this directory

$ sudo mv android_amd64.img /var/lib/anbox/android.img
3. Let's run it!
This process must be followed each time you want to run Anbox manually:

1. Assert kernel modules are loaded (required after each reboot)

$ ls -1 /dev/{ashmem,binder}
/dev/ashmem
/dev/binder
2. Start bridge script

$ sudo /usr/local/src/anbox/scripts/anbox-bridge.sh start
3. Manually start container manager

$ sudo anbox container-manager --daemon --privileged --data-path=/var/lib/anbox
This command will launch container as a daemon, do not expect any output and let it running (use CTRL+C if you want to stop it later)

4. Optionaly, if you are looking for logs, open another terminal and watch for logs

$ sudo tail -f /var/lib/anbox/logs/container.log
5. Open another terminal and finally, launch anbox app manager (will automatically start session manager)!

$ anbox launch --package=org.anbox.appmgr --component=org.anbox.appmgr.AppViewActivity
IV. Going further
1. Using a service for container
To simplify startup routine, we can use a systemd service:

1. Create a anbox-container-manager.service file with following content (adapt paths if needed)

$ sudo vim /lib/systemd/system/anbox-container-manager.service
[Unit]
Description=Anbox Container Manager
After=network.target
Wants=network.target
ConditionPathExists=/var/lib/anbox/android.img

[Service]
ExecStartPre=/sbin/modprobe ashmem_linux
ExecStartPre=/sbin/modprobe binder_linux
ExecStartPre=/usr/local/src/anbox/scripts/anbox-bridge.sh start
ExecStart=/usr/local/bin/anbox container-manager --daemon --privileged --data-path=/var/lib/anbox
ExecStopPost=/usr/local/src/anbox/scripts/anbox-bridge.sh stop

[Install]
WantedBy=multi-user.target
2. Symlink it

$ sudo ln -s /lib/systemd/system/anbox-container-manager.service /etc/systemd/system/
3. Reload daemons

$ sudo systemctl daemon-reload
4. Start it!

$ sudo systemctl start anbox-container-manager.service
5. Check status

$ sudo systemctl status anbox-container-manager.service
5. Optionally : start it with system

$ sudo systemctl enable anbox-container-manager.service
V. Conclusion
I hope this tutorial has helped you making Anbox working on your system.
How to use anbox is beyond the scope of this tutorial and I think you can find other ressources on the Internet.
Do not hesitate to comment to tell me if this worked for you too, correct my mistakes or to provide additional content.
Matteljay
Level 1
Level 1
Posts: 2
Joined: Wed Sep 07, 2022 4:38 am

Re: How-to install anbox from sources on Mint 20 without snap

Post by Matteljay »

My steps taken to build Anbox from source with files/ideas from the Arch Linux repo maintainers:
Install the long list of requirements from Anbox' github page, include package: libsdbus-c++-dev

Code: Select all

git clone https://github.com/anbox/anbox.git --recurse-submodules
Go to Arch Linux' repository: https://aur.archlinux.org/cgit/aur.git/ ... =anbox-git
'Download snapshot' is a good start, include more files from the Sources section
Put the *.patch files in folder ../path/to/patches
Make sure to rename sdbus.patch to 0-sdbus.patch so it gets applied first

Code: Select all

cd anbox/external/cpu_features
truncate -s 0 tests/CMakeLists.txt
mkdir build
cd build
cmake -DCMAKE_INSTALL_LIBDIR=lib -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=None -DCMAKE_SKIP_INSTALL_RPATH=YES -DCMAKE_SKIP_RPATH=YES -Wno-dev ..
make
sudo make install
Back inside anbox folder

Code: Select all

truncate -s 0 cmake/FindGMock.cmake
truncate -s 0 tests/CMakeLists.txt
for p in ../path/to/patches/*; do patch -Np1 < $p; done
mkdir anbox/build
cd anbox/build
cmake -DCMAKE_INSTALL_LIBDIR=lib -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=None -DCMAKE_SKIP_INSTALL_RPATH=YES -DCMAKE_SKIP_RPATH=YES -Wno-dev ..
make
sudo make install
Install as root from the anbox source folder

Code: Select all

install -Dm755 -t /etc/init.d/ scripts/anbox-bridge.sh
install -Dm644 -t /usr/share/desktop-directories/ data/desktop/anbox-android.directory
install -Dm644 -t /etc/xdg/menus/applications-merged/ data/desktop/anbox-android.menu
install -Dm644 snap/gui/icon.png /usr/share/pixmaps/anbox.png
Install as root from the arch git folder

Code: Select all

install -Dm644 -t /usr/lib/systemd/user/ anbox-session-manager.service
install -Dm644 -t /usr/share/dbus-1/services/ org.anbox.service
install -Dm644 -t /usr/lib/udev/rules.d/ 99-anbox.rules
install -Dm644 -t /usr/share/applications/ anbox.desktop
install -Dm644 -t /etc/modules-load.d/ anbox.conf
Download an Android image, for example from: https://build.anbox.io/android-images/
Rename it to android.img and put it in the data-path specified below by the container-manager service.

Make sure the script anbox-bridge.sh has these comments to help systemd.generator boot it in the right order:

Code: Select all

### BEGIN INIT INFO
# Provides:       anbox-bridge
# Required-Start: $network
# Required-Stop:  $network
# Default-Start:  2 3 4 5
# Default-Stop:   0 1 6
# Description:    Network access for Anbox containers
### END INIT INFO
Create file /usr/lib/systemd/system/anbox-container-manager.service

Code: Select all

[Unit]
Description=Anbox Container Manager
Requires=dev-binderfs.mount anbox-bridge.service

[Service]
ExecStart=/usr/bin/anbox container-manager --daemon --privileged --data-path=/home/user/anbox-data --container-network-gateway=192.168.250.1 --container-network-address=192.168.250.2

[Install]
WantedBy=multi-user.target
Create file /usr/lib/systemd/system/dev-binderfs.mount

Code: Select all

[Unit]
Description=Android Binder File System
ConditionPathExists=!/dev/binder
After=udev.service

[Mount]
Where=/dev/binderfs
What=binder
Type=binder
Options=nofail

[Install]
WantedBy=multi-user.target
Ready to start and enable services at boot:

Code: Select all

systemctl daemon-reload
udevadm control --reload-rules && udevadm trigger
modprobe ashmem_linux
modprobe binder_linux
systemctl enable --now dev-binderfs.mount
systemctl enable --now anbox-bridge.service
systemctl enable --now anbox-container-manager
Now you should be able to start Anbox from your launcher menu. It will take a moment the first time (30s for me). Next time will be a lot faster.
Confirmed to work on x86-64 for Linux Mint 20.3 Mate on september 2022. If someone would like to make a .deb file or PPA that'd be great!

Warning Just like on Arch, anbox-container seems to require --privileged modus to run, which may present a security issue.
For this reason I personally don't enable the container-manager background service and start it manually when needed.
Post Reply

Return to “Tutorials”