Get Informed out of Data

Full width home advertisement

Raspbian

DataScience

Post Page Advertisement [Top]

Install Anbox on Raspbian - Raspberry pi 4

Install Anbox on Raspbian - Raspberry pi 4
Anbox is an application which puts an Android image inside a container, abstracts the access to the hardware and integrates the system core in GNU/Linux systems.


Thanks to this philosophy, each Android application will be integrated with the host operating system as if we were trying to run a native application.
With Anbox no QEMU type emulation layer is required, everything runs directly on the hardware.

Why Anbox is not natively supported for Raspbian

One of the big drawbacks of this project is that it does not support Raspberry Pi 4, it only supports Ubuntu PC platforms. According to its website, it is because the developers took different paths, since at first it was tried to make Ubuntu Touch one of the targets for this project. For that reason, we must compile everything to be able to install:
  • Anbox dkms modules
                      binder_linux
                      ashmem_linux
  • Anbox itself
  • The Android image with the necessary architecture:
                       anbox_armv7a_neon-userdebug

Here Kernel used:

Linux raspberrypi 5.4.40-v7l+  armv7l 

Since to compile we need the headers of this kernel it is necessary to do it with the rpi-source tool:
Install the dependencies:
sudo apt-get install git bc bison flex libssl-dev

Install the rpi-source itself:

sudo wget https://raw.githubusercontent.com/notro/rpi-source/master/rpi-source -O /usr/local/bin/rpi-source && sudo chmod +x /usr/local/bin/rpi-source && /usr/local/bin/rpi-source -q --tag-update

If we run it and everything went well we should get a screen such as this:


Next step is to compile and install kernel modules:

For this step we need to continue cloning the anbox-modules repository, but first we must install (if we don't have it) dkms:

sudo apt-get install dkms

Before continuing, when we have cloned the repository, we must modify the binder module because a flag must be enabled in order to fix that Android supports 64bits binder in 32bits. This flag enables it:

#define CONFIG_ANDROID_BINDER_IPC_32BIT

This flag must be in binder / binder.c at the beginning of the code.

As in the previous step we have installed our headers for the current kernel we can continue:

#configuration files
sudo cp anbox.conf /etc/modules-load.d/
sudo cp 99-anbox.rules /lib/udev/rules.d/
#copy moduloes to /usr/src
sudo cp -rT ashmem /usr/src/anbox-ashmem-1
sudo cp -rT binder /usr/src/anbox-binder-1
#build and install
sudo dkms install anbox-ashmem/1
sudo dkms install anbox-binder/1

Once finished we will have our modules installed, in my case I do not want the loading to be automatic (since I want to load and download the modules with modprobe depending on my needs), so this step I will do manually every time I want to run anbox :

sudo modprobe ashmem_linux
sudo modprobe binder_linux

If you want to check that everything loaded perfectly:

lsmod | grep -e ashmem_linux -e binder_linux

Now,Let's insall Anbox from sources,

we need to install these libraries:

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 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 python2

But two of them will not work as they should since they do not have support for wayland included (it was disabled during the compilation) so we will install all but:

  • libsdl2-dev
  • libsdl2-image-dev

We will compile these two by hand:

libsd2

It is a mercurial repository, so we need to have hg installed:

hg clone https://hg.libsdl.org/SDL SDL
cd SDL
mkdir build
cd build
../configure
make
sudo make install

libsdl2-image

It is a tar.gz so we can download it with wget from this address:

wget https://www.libsdl.org/projects/SDL_image/release/SDL2_image-2.0.5.tar.gz
tar zxvf SDL2_image-2.0.5.tar.gz

And we install:

cd SDL2_image-2.0.5
./configure
make
make install

Anbox

For this we will clone the anbox repository

We replace the CMakeLists.txt with the following

project(anbox C CXX)
cmake_minimum_required(VERSION 2.8.2)

include(CTest)
include(GNUInstallDirs)

if (NOT CMAKE_BUILD_TYPE)
    message(STATUS "No build type selected, default to RelWithDebInfo")
    set(CMAKE_BUILD_TYPE "RelWithDebInfo")
endif()

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -pedantic -Wno-variadic-macros -Wextra -fPIC")

# By default, all symbols are visible in the library. We strip out things we don't
# want at link time, by running a version script (see unity-scopes.map and the
# setting of LINK_FLAGS below).
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=default")

#set(C_AND_CXX_WARNINGS "-pedantic -Wall -Wextra")

# Some additional warnings not included by the general flags set above.
#set(EXTRA_C_WARNINGS "-Wcast-align -Wcast-qual -Wformat -Wredundant-decls -Wswitch-default")
#set(EXTRA_CXX_WARNINGS "-Wnon-virtual-dtor -Wold-style-cast")

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${C_AND_CXX_WARNINGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_C_WARNINGS}")

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 ${C_AND_CXX_WARNINGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_C_WARNINGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CXX_WARNINGS}")

# -fno-permissive causes warnings with clang, so we only enable it for gcc
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-permissive")
endif()

string(TOLOWER "${CMAKE_BUILD_TYPE}" cmake_build_type_lower)

#if ("${cmake_build_type_lower}" STREQUAL "release" OR "${cmake_build_type_lower}" STREQUAL "relwithdebinfo")
#  option(Werror "Treat warnings as errors" ON)
#else()
#  option(Werror "Treat warnings as errors" OFF)
#endif()

#if (${Werror})
#    message(STATUS "Treat warnings as errors")
#  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
#  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
#  if ("${cmake_build_type_lower}" STREQUAL "release" OR "${cmake_build_type_lower}" STREQUAL "relwithdebinfo")
#    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-error=deprecated-declarations")
#    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=deprecated-declarations")
#  endif()
#endif()

set(CMAKE_INCLUDE_CURRENT_DIR ON)

find_package(Boost COMPONENTS filesystem log serialization system thread program_options)
find_package(PkgConfig)
find_package(Threads)
find_package(EGL REQUIRED)
find_package(GLESv2 REQUIRED)
find_package(Protobuf REQUIRED)

pkg_check_modules(SDL2 sdl2 REQUIRED)
pkg_check_modules(SDL2_IMAGE SDL2_image REQUIRED)
pkg_check_modules(DBUS dbus-1 REQUIRED)
pkg_check_modules(LXC lxc REQUIRED)
pkg_check_modules(PROPERTIES_CPP properties-cpp REQUIRED)
pkg_check_modules(LIBSYSTEMD libsystemd REQUIRED)
pkg_check_modules(LIBCAP libcap REQUIRED)

message(STATUS "LXC version: ${LXC_VERSION}")
if (${LXC_VERSION} VERSION_LESS 3.0)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DENABLE_LXC2_SUPPORT")
  message(STATUS "Building with LXC 2.x compatibility support")
endif()

option(ENABLE_X11 "Enable X11 support" ON)
if (ENABLE_X11)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DX11_SUPPORT")
endif()

option(ENABLE_WAYLAND "Enable wayland support" OFF)
if (ENABLE_WAYLAND)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DWAYLAND_SUPPORT")
endif()

option(ENABLE_MIR "Enable mir support" OFF)
if (ENABLE_MIR)
  pkg_check_modules(MIRCLIENT mirclient REQUIRED)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMIR_SUPPORT")
endif()

if (NOT BINDERFS_PATH)
  set(BINDERFS_PATH "/dev/binderfs")
endif()

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DEGL_NO_X11")

if((Protobuf_VERSION VERSION_GREATER "3.7") OR (Protobuf_VERSION VERSION_EQUAL "3.7"))
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_PROTOBUF_CALLBACK_HEADER")
endif()

#####################################################################
# Enable code coverage calculation with gcov/gcovr/lcov
# Usage:
#  * Switch build type to coverage (use ccmake or cmake-gui)
#  * Invoke make, make test, make coverage
#  * Find html report in subdir coveragereport
#  * Find xml report feasible for jenkins in coverage.xml
#####################################################################
IF(CMAKE_BUILD_TYPE MATCHES [cC][oO][vV][eE][rR][aA][gG][eE])
  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftest-coverage -fprofile-arcs" )
  SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ftest-coverage -fprofile-arcs" )
  SET(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -ftest-coverage -fprofile-arcs" )
  SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -ftest-coverage -fprofile-arcs" )
ENDIF(CMAKE_BUILD_TYPE MATCHES [cC][oO][vV][eE][rR][aA][gG][eE])

find_package(GMock)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -fPIC")


if (NOT ANBOX_VERSION)
    exec_program("git" ${CMAKE_SOURCE_DIR} ARGS "rev-parse --short HEAD" OUTPUT_VARIABLE GIT_COMMIT_HASH)
    set(ANBOX_VERSION "local-${GIT_COMMIT_HASH}")
endif()
if (ANBOX_VERSION_SUFFIX)
    set(ANBOX_VERSION "${ANBOX_VERSION}-${ANBOX_VERSION_SUFFIX}")
endif()
set(ANBOX_RESOURCE_DIR "${CMAKE_INSTALL_DATADIR}/anbox")
set(ANBOX_RESOURCE_DIR_FULL "${CMAKE_INSTALL_FULL_DATADIR}/anbox")
set(ANBOX_STATEDIR_FULL "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/lib/anbox")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/anbox/build/config.h.in
               ${CMAKE_CURRENT_SOURCE_DIR}/src/anbox/build/config.h)

add_subdirectory(external)
add_subdirectory(src)
add_subdirectory(tests)
add_subdirectory(android)

if (NOT "${HOST_CMAKE_C_COMPILER}" STREQUAL "")
  message(STATUS "Host C compiler: ${HOST_CMAKE_C_COMPILER}")
  message(STATUS "Host C compiler: ${HOST_CMAKE_CXX_COMPILER}")
endif()

option(SNAP_CONFINEMENT "Enable snap confinement support" OFF)
if (SNAP_CONFINEMENT)
  message(STATUS "Building with support for snap confinement")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DENABLE_SNAP_CONFINEMENT")
endif()

install(FILES data/ui/loading-screen.png DESTINATION ${ANBOX_RESOURCE_DIR}/ui)

# uninstall target
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
               "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
               IMMEDIATE @ONLY)
add_custom_target(uninstall "${CMAKE_COMMAND}"
                  -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")

We save and head to src / anbox / input / device.cpp and replace 2 uint64_t with uint32_t in the struct CompatEvent such that like so:

struct CompatEvent {
    // NOTE: A bit dirty but as we're running currently a 64 bit container
    // struct input_event has a different size. We rebuild the struct here
    // to reach the correct size.
    std::uint32_t sec;
    std::uint32_t usec;
    std::uint16_t type;
    std::uint16_t code;
    std::uint32_t value;
  };

We save and with it we have everything ready to compile and install in the traditional way:

mkdir build
cd build
cmake ..
make
sudo make install

No comments:

Post a Comment

Bottom Ad [Post Page]