TYPE3
[iec.git] / src / type3_AndroidCloud / anbox-master / docs / build-android.md
1 # Build Android Image
2
3 For Anbox we're using a minimal customized version of Android but otherwise
4 base all our work of a recent release of the [Android Open Source Project](https://source.android.com/).
5
6 To rebuild the Android image you need first fetch all relevant sources. This
7 will take quite a huge amount of your disk space (~40GB). AOSP recommends at
8 least 100GB of free disk space. Have a look at [their](https://source.android.com/source/requirements.html) pages too.
9
10 In general for building the Anbox Andorid image the instructions found on [the pages
11 from the AOSP project](https://source.android.com/source/requirements.html) apply.
12 We will not describe again here of how to build the Android system in general but
13 only focus on the steps required for Anbox.
14
15 ## Fetch all relevant sources
16
17 First setup a new workspace where you will download all sources too.
18
19 ```
20 $ mkdir $HOME/anbox-work
21 ```
22
23 Now initialize the repository by download the manifest and start fetching
24 the sources:
25
26 ```
27 $ cd $HOME/anbox-work
28 $ repo init -u https://github.com/anbox/platform_manifests.git -b anbox
29 $ repo sync -j4
30 ```
31
32 This will take quite some time depending on the speed of your internet connection.
33
34 ## Build Android
35
36 When all sources are successfully downloaded you can start building Android itself.
37
38 Firstly initialize the environment with the ```envsetup.sh``` script.
39
40 ```
41 $ . build/envsetup.sh
42 ```
43
44 Then initialize the build using ```lunch```.
45
46 ```
47 $ lunch anbox_x86_64-userdebug
48 ```
49
50 The complete list of supported build targets:
51
52  * anbox_x86_64-userdebug
53  * anbox_armv7a_neon-userdebug
54  * anbox_arm64-userdebug
55
56 Now build everything with
57
58 ```
59 $ make -j8
60 ```
61
62 Once the build is done we need to take the results and create an image file
63 suitable for Anbox.
64
65 ```
66 $ cd $HOME/anbox-work/vendor/anbox
67 $ scripts/create-package.sh \
68     $PWD/../out/target/product/x86_64/ramdisk.img \
69     $PWD/../out/target/product/x86_64/system.img
70 ```
71
72 This will create an *android.img* file in the current directory.
73
74 With this, you are now able to use your custom image within the Anbox runtime.
75
76 ## Run Anbox with self build android.img
77
78 If you have Anbox installed on your system you need to stop it first. If you used
79 the installer script and the snap you can do this via
80
81 ```
82 $ initctl stop anbox
83 $ sudo systemctl stop snap.anbox.container-manager
84 ```
85
86 It is important that you stop both, the container manager and the session manager.
87
88 Once both services are stopped you can start the container manager with your
89 custom android.img file by running
90
91 ```
92 $ datadir=$HOME/anbox-data
93 $ mkdir -p $datadir/rootfs
94 $ sudo anbox container-manager \
95     --android-image=/path/to/android.img \
96     --data-path=$datadir
97 ```
98
99 This will start the container manager and setup the container rootfs inside the
100 specified data path.
101
102 ```
103 $ ls -alh $HOME/anbox-data
104 total 20K
105 drwxrwxr-x  5 ubuntu  ubuntu  4,0K Feb 22 08:04 .
106 drwxrwxr-x 16 ubuntu  ubuntu  4,0K Feb 22 08:04 ..
107 drwxr-xr-x  2 100000  100000 4,0K Feb 22 08:04 cache
108 drwxr-xr-x  2 100000  100000 4,0K Feb 22 08:04 data
109 drwxr-xr-x  2 root    root   4,0K Feb 22 08:04 rootfs
110 ```
111
112 **NOTE:** If you look into the $HOME/anbox-data/rootfs directory you won't see
113 anything as the container manager spawns up a private mount namespace which
114 prevents anything from the outside to see its mount points.
115
116 The *cache* and *data* directories are bind-mounted into the rootfs at *rootfs/data*
117 and *rootfs/cache*.