Integrate Lantern

Here you’ll find documentation for working with the Lantern Android library. Below are instructions for integrating it into your Android applications.

Manual Setup

This guide assumes you are using Gradle. For more information about Gradle, refer to the Android developer site.

Download liblantern.aar and sdk-debug.aar

Download liblantern.aar and sdk-debug.aar and place them in the libs folder of your Android project.

Modify build.gradle

Update your project’s build.gradle script to include the Lantern classpath dependency. Make sure you include the Maven central repository:

repositories {
    ...

    flatDir{
        dirs 'libs'
    }
}

dependencies {
    compile(name:'liblantern', ext:'aar')
    compile(name:'sdk-debug', ext:'aar')
    ...
}

Updating your application

You can embed Lantern to run directly within your application, or have Lantern run as a service inside of its own process. Running as a service is useful if your application is already resource intensive and needs to minimize its memory usage.

Both ways of embedding Lantern are similar. A good place to start Lantern is in Android’s Application class.

package com.example.app;

import org.lantern.mobilesdk.Lantern;
import android.app.Application;

public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();

        boolean asService = true; // up to you

        // enable Lantern
        int startupTimeoutMillis = 30000;

        // whether or not to update the application HTTP proxy settings
        // if true, the http.proxyHost, http.proxyPort system
        // properties will be set
        boolean updateProxySettings = true;

        // Optional Google Analytics tracking ID that gives Team Lantern
        // feedback on your app's usage of Lantern.
        String trackingId = "UA-...";

        if (asService) {
            Lantern.enableAsService(getApplicationContext(),
                startupTimeoutMillis, updateProxySettings, trackingId, null);
        } else {
            Lantern.enable(getApplicationContext(),
                startupTimeoutMillis, updateProxySettings, trackingId, null);
        }
    }
}

Note

Make sure to add the fully qualified name of Application sub-class to the android:name attribute in the applications manifest.

Note

You can find a working example of Lantern integrated into an application called FireTweet here

To run Android as a service, you’ll need to add the following to your AndroidManifest.xml.

<application>
    ...

    <service
        android:name="org.lantern.mobilesdk.service.LanternService"
        android:exported="false"
        android:process=":LanternService"
        />

    ...
</application>