Setup an Android Studio testing suite

l### Guide

This guide will walk you through the process of setting up your development environment to run Zingo Mobile on an Android emulator.

Prerequisites

Before you start, ensure you have the following prerequisites installed on your system:

If you are missing any of these, refer to the Zingo Mobile readme for installation instructions.

Building the Rust Dependencies

  1. Clone the repository: Clone the Zingo Mobile repository to your local machine.
  2. Navigate to the Rust directory: Open a terminal and navigate to the rust directory within the cloned repository.
  3. Run the build script: Execute ./build.sh to build the Rust dependencies. This step may take a while to complete.

Installing Android Studio and Setting Up the Environment

  1. Install Android Studio: It is recommended to install Android Studio using your system's package manager (e.g., pacman on Arch Linux or apt on Debian/Ubuntu) for better integration and dependency management. If you have previously installed Android Studio via Flatpak and encountered issues, consider removing it and reinstalling it using your package manager.
  2. Launch Android Studio: Open Android Studio and follow the initial setup wizard.
  3. Create an Android Virtual Device (AVD): In Android Studio, create an AVD with API level 30 (Android 11) or higher to emulate an Android device. Make sure the AVD's CPU architecture matches your system's architecture (e.g., x86_64).
  4. Configure Environment Variables: Add the following lines to your ~/.bash_profile or ~/.profile config file:
PATH="$PATH:$ANDROID_HOME/cmdline-tools/latest/bin"
PATH="$PATH:$ANDROID_HOME/platform-tools"
PATH="$PATH:$ANDROID_HOME/emulator"

Add the following lines to your ~/.bashrc config file:

export ANDROID_SDK_ROOT="$HOME/Android/Sdk"
export JAVA_HOME="/usr/lib/jvm/jdk-18.0.2"  # Adjust the path if your JDK is installed elsewhere
  1. Set Gradle JDK: In Android Studio, go to File > Settings > Build, Execution, Deployment > Build Tools > Gradle and ensure the Gradle JDK matches your installed JDK version (OpenJDK 18).

Running the Zingo Mobile App

  1. Install JavaScript dependencies: Open a terminal at the root of the Zingo Mobile repository and run yarn to install the required JavaScript dependencies.
  2. Start the Metro Bundler: In the same terminal, run yarn start to start the Metro bundler. If you encounter issues during this step, try rebuilding the Rust dependencies in release mode by running cargo build --release within the rust directory.
  3. Open the Android Project: In Android Studio, open the android directory from the Zingo Mobile repository.
  4. Build and Run: In Android Studio, select the 'app' module and your AVD in the toolbar. Click the "Run 'app'" button to build and deploy the app to the emulator.

You should now see the Zingo Mobile app running on your emulator!

Troubleshooting

sudo usermod -aG docker <your_username>
sudo systemctl restart docker

If you continue to experience problems, consult the Zingo Mobile troubleshooting guide or seek help from the Zingo community.

Logs

Nacho

2024-09-03

14:05
Installing the prerequisites

paru -S docker
...
error: failed retrieving file 'docker-1:27.1.2-1-x86_64.pkg.tar.zst' from seoul.mirror.pkgbuild.com : The requested URL returned error: 404

Apparently, i had to update all my packages using:

paru -Syu

it solved it, docker is in

14:50
got java installed, now trying to add it to the PATH

15:27
java wasn't installed, spent half an hour trying to install it
now trying to install from aur
#Seba says it might have been installed by AS for him at the time, ill try that later

15:32
gave up on java, didnt work on aur either.
im now installing AS directly from flatpack store

15:35
setting up docker while AS downloads.
Tried this:

docker run hello-world
docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.
See 'docker run --help'.

docker needs some permissions to execute
you need to create a linux group, add your user to it
we create a group called docker

groupadd docker

apparently, a docker group existed already

15:43
while installing AS i got a message saying my PC is capable of running it in enhanced mode, and a link to see how it works

15:46

sudo usermod -aG docker chona

this adds my user into the docker

15:49

systemctl status docker
○ docker.service - Docker Application Container Engine
     Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; preset: disabled)
     Active: inactive (dead)
TriggeredBy: ○ docker.socket
       Docs: https://docs.docker.com

apparently, the docker service needs to be turned on.

16:03

systemctl enable docker
Created symlink '/etc/systemd/system/multi-user.target.wants/docker.service' → '/usr/lib/systemd/system/docker.service'.

this enables the docker service
now we want to check that it works
It still doesnt work, we enabled it but didnt start it

16:06

systemctl start docker
Job for docker.service failed because the control process exited with error code.
See "systemctl status docker.service" and "journalctl -xeu docker.service" for details.

this sucks
lets try restarting the service

systemctl restart docker
Job for docker.service failed because the control process exited with error code.
See "systemctl status docker.service" and "journalctl -xeu docker.service" for details.

16:07

systemctl status docker
× docker.service - Docker Application Container Engine
     Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; preset: disabled)
     Active: failed (Result: exit-code) since Tue 2024-09-03 16:06:15 -03; 49s ago
 Invocation: 8e2256e1ca3047269aad423cdc317aba
TriggeredBy: × docker.socket
       Docs: https://docs.docker.com
    Process: 48416 ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock (code=exited, status=1/FAILURE)
   Main PID: 48416 (code=exited, status=1/FAILURE)

Sep 03 16:06:15 chonalinux systemd[1]: docker.service: Scheduled restart job, restart counter is at 3.
Sep 03 16:06:15 chonalinux systemd[1]: docker.service: Start request repeated too quickly.
Sep 03 16:06:15 chonalinux systemd[1]: docker.service: Failed with result 'exit-code'.
Sep 03 16:06:15 chonalinux systemd[1]: Failed to start Docker Application Container Engine.
Sep 03 16:07:02 chonalinux systemd[1]: docker.service: Start request repeated too quickly.
Sep 03 16:07:02 chonalinux systemd[1]: docker.service: Failed with result 'exit-code'.
Sep 03 16:07:02 chonalinux systemd[1]: Failed to start Docker Application Container Engine.

16:48
i just had to reboot and the new groups got registered fine!
docker is now working:

docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
c1ec31eb5944: Pull complete
Digest: sha256:53cc4d415d839c98be39331c948609b659ed725170ad2ca8eb36951288f81b75
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

2024-09-04

10:45
I've got Android Studio installed trough the Flatpack Store
When launching it, i got an error saying some sort of session was already running, i got it solved by deleting a file like this:

rm ~/.var/app/com.google.AndroidStudio/config/Google/AndroidStudio2024.1/.lock

11:03
I created an AVD with API 30 of middle screen size.

I got an error when running yarn start saying JAVA_HOME wasn't in my PATH

18:38
Finally got zingo running on the emulator

19:59
Im still getting errors on the AS build panel:

Caused by: java.io.IOException: Cannot run program "node" (in directory "/home/chona/zingo/zingo-mobile/android"): error=2, No such file or directory

apparently AS has issues finding the right version of node to use ..
found this stack overflow post where they say:

Ok, as proposed in this threat, creating a symbolic link to the used nvm version fixes thee problem. The issue is that when using nvmAndroid Studio does not where to find the node executable.

sudo ln -s "$(which node)" /usr/local/bin/node

Tried the above and that didnt work either..

2024-09-05

18:05
#Seba got it working with plain node, so i just have to find the way to make it work with nvm
Even if that doesnt work, we already have a reproducible path to get it working!!

18:41
I give up on using the flatpacked version, i even tried adding the PATH to the flatpack variable using

flatpak override --user --env=PATH=$PATH com.google.AndroidStudio

all it did was AS flashing on opening and closing itself inmediately.
Im installing androidstudio from paru now.

Aur (1) android-studio-2024.1.2.12-1

19:05
struggled a bit with it since i accidentally stoped the AS paru installation middway, then had to remove every AS related thing for it to even install porperly again;

paru -R android-studio

to remove the paru install of AS

paru -Sc android-studio

to remove all cache of it

cd ../../opt
sudo rm -rf android-studio 

to remove all downloaded tar's from AS since paru was trying to use some corrupted files from here

19:10
I got the build tab working finally!!!

19:16
Now that AS builds properly after opening the android dir from the repo, i do see the "pick device and app" options on the upper toolbar.