30 Developer Documentation
vanous edited this page 1 week ago

Development Environment

The core team uses Debian GNU/Linux + Android Studio, latest version. It is also available for Windows and Mac, but we never used that. You can use any Android device connected to USB to run your code straight from Android Studio on the device. Be aware that you cannot install your own built version and F-Droid’s at the same time. You can export and import your database, though.


You need to install

  • a Java Development Kit (JDK)
  • git
  • adb (Android Debug Bridge, included in Android Studio)

On Ubuntu, you can use following commands (java 9 seems broken, please use java 8)

sudo apt-get install java-1.8.0-openjdk-amd64 git adb

Getting the code

git clone https://codeberg.org/Freeyourgadget/Gadgetbridge.git

(after you did that once, you can use git pull to get the newest Gadgetbridge code)

Alternatively you can use Android Studio to clone the Gadgetbridge repository.

Building and installing the Gadgetbridge apk

If you only want to compile the code, you can simply execute

./gradlew assembleDebug


./gradlew assembleRelease

And install it to your mobile or tablet by executing

adb install app/build/outputs/apk/app-debug.apk

Android Studio does all this automatically when you press the Run or Debug button.

Short Introduction to Gadgetbridge’s Source Code

Important Classes


Overview UML Component Diagram

All the details about the communication/protocol with a concrete device (Pebble, Mi Band, ...) is inside the “Concrete Device Impl.” component, that is, the concrete implementations of the DeviceSupport interface. Only the DeviceCommunicationService has access to those -- clients (typically Activities) talk to the DeviceService interface in order to communicate with the devices.

Bluetooth Error Codes



We use slf4j for logging, so just use LoggerFactory.getLogger(Your.class) and log away. The output will be written to the Android Log (so you can get it with logcat or Android Studio) as well as to the file /sdcard/Android/data/nodomain.freeyourgadget.gadgetbridge/files/gadgetbridge.log. File logging needs to be enabled in Gadgetbridge’s preferences, first.

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private static final Logger LOG = LoggerFactory.getLogger(Your.class);
LOG.error("Error accessing database", e);`

Information Display

Use one of the nodomain.freeyourgadget.gadgetbridge.util.GB#toast() methods to display information to the user. They

  • the toast when given an exception also logs warnings and errors, so with the toast you not have to use LOG afterwards.
  • can safely be called from a background thread
import nodomain.freeyourgadget.gadgetbridge.util.GB;
GB.toast("My toast message", Toast.LENGTH_SHORT, GB.ERROR, e);
My toast message


We use greenDAO for database access. See nodomain.freeyourgadget.gadgetbridge.daogen.GBDaoGenerator for entity definition and generation. Do note that we use greenDAO in version 2, the official greenDAO documentation already mentions version 3.

To add a column to a database, simply add a new field to a particular class in nodomain.freeyourgadget.gadgetbridge.daogen.GBDaoGenerator, then build the project, which will trigger generating of corresponding ...dao.class files. Also, make sure to set a new schema version Schema schema = new Schema(xx... and prepare a migration file in src/main/java/nodomain/freeyourgadget/gadgetbridge/database/schema/.


All icons should be provided as vector drawables, do not use PNGs anymore. If you are drawing the original design in SVG, make sure to export as regular uncompressed SVG, because Android Studio handles these files better. Then, import it to Android Studio via right click in Project panel → New → Vector Asset → Local file. Then, use Avocado optimizer for Android VectorDrawable (VD) and AnimatedVectorDrawable (AVD) xml files. Avocado rewrites the VectorDrawable using the smallest number of s and s possible, reducing their file sizes and making them faster to parse and draw at runtime.