Skip to content
This repository has been archived by the owner on Oct 19, 2022. It is now read-only.

Development Setup for Android

Daniel edited this page Nov 25, 2019 · 10 revisions

This page describes how to set up a development environment for testing the OX COI Messenger app in a local Android emulator.

Prerequisites

The prerequisites section so far only describes Debian Linux. You are welcome to add descriptions for other operating systems.

The main prerequisites are:

  • Git to access the source code,
  • A C development toolchain to compile some native dependencies (see plugin wiki),
  • A Rust development toolchain to compile DeltaChat Core (see plugin wiki),
  • Android Studio with Flutter support to compile the app,
  • A hypervisor to accelerate the emulation of Android devices.

Debian Linux

This setup assumes Debian 10. Other versions and other Debian-based distributions should work pretty much the same. Other Linux distributions might need to use a different package manager and maybe slightly different package names.

Git, the C tool-chain and the KVM hypervisor can be installed from the main package repository. Also, curl is needed to install the Rust tool-chain.

sudo apt install git build-essential libvirt-daemon curl

Android Studio

It might actually be possible to build and run the app entirely from the command line and/or using packages from Debian repositories. Any experience reports or documentation are welcome. But for now, the full Android Studio from Google is going to be used here.

Download Android Studio from https://developer.android.com/studio and unpack it somewhere you'll be able to find later. Start Android Studio from the unpacked directory with

android-studio/bin/studio.sh

Android SDK

On first run, the Android Studio Setup Wizard will start automatically and offer to download an SDK and other components. The rest of the documentation will assume a standard install, but the only important option is the path of the SDK Folder, which is displayed on the Verify Settings page. It defaults to $HOME/Android/Sdk and is used to run various command line tools, as seen below.

The last page of the Setup Wizard contains a link to installation instructions for the hypervisor for your platform. Since KVM was installed as the very first step above, it should already work. To verify this, use the following command:

$HOME/Android/Sdk/emulator/emulator -accel-check

The expected output is:

accel:
0
KVM (version 12) is installed and usable.
accel

After the Setup Wizard is finished, the Welcome to Android Studio window is displayed. Further configuration will be done via the Configure menu in the bottom right. If you already opened a project, the same entries are available in the Tools menu instead.

Android Virtual Device (AVD)

Use the Android Virtual Device Manager to create an Android virtual device by selecting Configure/ToolsAVD ManagerCreate Virtual Device… On the first two pages, you can select any device and image, but latest versions are recommended. The system image probably needs to be downloaded first. After finishing the creation, the virtual device can be launched from the Your VirtualDevices page by clicking on the green Play button.

Flutter

Install Flutter by following instructions on https://flutter.dev/docs/get-started/install. To get a perfect score in the output of the flutter doctor command, follow these steps after unpacking the SDK and adding it to your PATH:

flutter config --no-analytics
flutter doctor --android-licenses

Install Flutter support in Android Studio by selecting Configure/ToolsPluginsFlutterInstall. This should also install Dart support. Restart the IDE afterwards.

Now launch the created Android device from the AVD Manager and run

flutter doctor

It should not find any issues.

Source Code

The source code of the app is distributed over several Git repositories. Currently, they expect to be checked out into the same parent directory. This parent directory will be referred to as $GIT from now on.

cd $GIT
git clone https://github.com/open-xchange/ox-coi.git
git clone https://github.com/open-xchange/flutter-deltachat-core.git

Flutter Only

If you are not going to work on DeltaChat Core or any other Rust code, then you can let Git submodules and Rust's package manager Cargo take care of downloading the necessary Rust code:

cd $GIT/flutter-deltachat-core
git submodule update --init --recursive

Rust and Flutter

If, on the other hand, you want to test Rust code which you modified locally, then you should have a look into the plugin wiki (Local rust core changes).

Building

Once all app related installation steps from above are complete, head over to the plugin repository wiki and take care of compiling the rust core. If you already have an up and running Rust setup just perform the following steps.

cd $GIT/flutter-deltachat-core/

Build for Android only:

./build-dcc.sh android

Build for iOS only:

./build-dcc.sh ios

Build for both:

./build-dcc.sh all

This will take some time the first time, since everything is built for all 4 supported target platforms (32bit and 64bit for each ARM and Intel).

In the mean time, open the $GIT/ox-coi project in Android Studio. If it's the first time, several notifications will pop up:

  • Welcome to Flutter! is just polite spyware: select No thanks.
  • Frameworks Detected has only one option: Configure. It opens a dialog. Just select OK there.
  • 'Packages get' has not been run appears at the top of the automatically opened editor for main.dart: select Get dependencies.

If you miss any notification pop-ups, they can be found again in the Event Log in the bottom right corner.

For now, one more manual one-time adjustment is necessary: Select RunEdit Configurations… and in the configuration for main.dart find the setting Build flavor and enter the value development.

Running

Before launching the app, several checks are useful to avoid most frequent errors:

  • Check that the Rust build finished without errors.
  • Ensure that the virtual Android device is running
  • Select the Android device in the Flutter Device Selection drop-down in the toolbar.

Finally, you can launch the app by selecting either the green Run or the Debug button in the toolbar.

On repeated runs, the ndk-make.sh step is only necessary whenever any local Rust code was modified. The Flutter parts are built automatically before the updated app is launched.

Clone this wiki locally