Creating an Arch Linux chroot to compile Conversations.

0) Prepare a folder for your chroot.

I alway put my chroots in / for shorter paths For example: /arch

sudo mkdir /arch
cd /arch

1) Download Arch bootstrap

Go to https://archlinux.org/download/ then select and open a mirror close to you Download a file named archlinux-bootstrap-x86_64.tar.gz

For example: bootstrap from a Dutch server: http://arch.mirrors.lavatech.top/iso/2022.12.01/archlinux-bootstrap-x86_64.tar.gz

2) unpack it

sudo tar xpvf archlinux-bootstrap-x86_64.tar.gz --xattrs-include='*.*' --numeric-owner

4) Edit pacman mirrorlist (from outside the chroot)

All mirrors are commented out by default. We have to select a mirror server that works best for us. Ideally, select a mirror that is in your own country.

For example: Uncomment 3 first mirrors from France

sudo nano root.x86_64/etc/pacman.d/mirrorlist

5) edit pacman.conf

There are some settings we need to change in order for pacman to work in our chroot.

sudo nano root.x86_64/etc/pacman.conf

uncomment Color
comment CheckSpace
uncomment ParallelDownloads and set it to your liking (I set it to 20)

CheckSpace must be uncommented in a chroot because of this: error: could not determine cachedir mount point /var/cache/pacman/pkg error: failed to commit transaction (not enough free disk space)

6) Prepare an easy-to-use shell script to chroot into Arch (optional)

cd $HOME
mkdir bin
cd bin
nano arch-start



    #!/bin/bash

    xhost +local:

    sudo mount -t proc none /arch/root.x86_64/proc
    sudo mount -t sysfs none /arch/root.x86_64/sys
    sudo mount --rbind /dev /arch/root.x86_64/dev
    sudo mount --rbind /run /arch/root.x86_64/run

    sudo cp /etc/resolv.conf /arch/root.x86_64/etc/resolv.conf

    sudo chroot /arch/root.x86_64 /bin/bash

In order to have a working internet connection, we have to copy resolv.conf to our chroot.

Let's just copy it every time we start our chroot.

xhost is needed in case you want to run a GUI application from within your chroot.

chmod +x arch-start

Add $HOME/bin to your PATH

nano $HOME/.bashrc

PATH=/home/your_username/bin:$PATH

You are able to type arch-start in your terminal and you will automatically mount all needed folders and chroot into Arch.

From within the chroot:

6) Init pacman keys

pacman-key --init

6.1) Populate pacman keys

pacman-key --populate

7) Install required packages

pacman -Syyuu
pacman -S neofetch nano sudo python3 python-pip xorg git base-devel wget yajl gradle jdk17-openjdk jdk8-openjdk

After everything above is installed:

pip install setuptools

8) make a normal user and add it to sudoers

useradd -m -s /bin/bash username
(set the password)
passwd username

nano +83 /etc/sudoers
add: username ALL=(ALL:ALL) ALL

From this point change to username

su username

9) Install yaourt (or yay, whatever you want)

( https://www.tecmint.com/install-yaourt-in-arch-linux/ )

mkdir $HOME/git
cd $HOME/git
git clone https://aur.archlinux.org/package-query.git
cd package-query
makepkg -si && cd ..

git clone https://aur.archlinux.org/yaourt.git
cd yaourt
makepkg -si

10) Install Android SDK following this guide: (Login to your normal user when using AUR)

https://gist.github.com/dianjuar/a86814b592dad96cfa9d9540cb5acbe0

yaourt android-sdk-platform-tools
yaourt android-udev
yaourt android-sdk

11) make /opt/android-sdk available to your account

sudo chmod -R 777 /opt/android-sdk

12) Create global variables on system

On ~/.bashrc of you are using bash or ~/.zshrc if you are using zsh in the last line put

export ANDROID_HOME=/opt/android-sdk
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/platform-tools

type

source $HOME/.bashrc

13) Set java to version 8

sudo archlinux-java set java-8-openjdk

This is needed to accept licenses.

( https://github.com/iNPUTmice/Conversations/issues/4252 )

go to $ANDROID_HOME/tools/bin/

Either do:

./sdkmanager --licenses 

and accept all licenses or do:

yes | ./sdkmanager --licenses

to accept all licenses

14) switch back to java-17

sudo archlinux-java set java-17-openjdk

15) Clone Conversations

cd $HOME
cd git
git clone https://codeberg.org/iNPUTmice/Conversations.git
cd Conversations
./gradlew assembleConversationsFree

WARNING! Do not just rm -rf your chroot!

There are still mounted files!!!!!

Before deleting your chroot, best thing to do is to reboot your whole machine to make sure there's nothing mounted.


Optional:

sudo pacman -S scrcpy
sudo adb start-server
scrcpy &
adb install build/outputs/apk/conversationsFree/debug/Conversations....
sudo adb kill-server