Android SDK

This section describes how to set up and install the Android SDK and how to deploy a feature flag.

Getting started with Android SDK

Step 1 - Setting up

To setup Android SDK, follow these steps:

  1. Create a CloudBees Feature Management account. See Signup Page to create an account.

  2. Get your environment key.

    • Get the key from App Settings > Environment > Key.

Step 2 - Installing the Android SDK

Initialize the Android package

Add the following in the dependencies block of your build.gradle file:

compile group: 'io.rollout.rox', name: 'rox-android', version: '4.8.0'

Add the following lines to the AndroidManfiest.xml file:

<!--    The uses-permission tag is for enabling internet access for your application and have to be outside the application tag -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<!-- Note the meta-data tag has to be inside the application tag -->
<meta-data
  android:name="rox.apiKey"
  android:value="ROLLOUT_ENV_KEY"
/>

Initialize the CloudBees Feature Management SDK by adding the following to the onCreate() method of your application class or main activity.

If your app contains a class that inherits from the application class, that is the right place to initialize the CloudBees Feature Management SDK. If not, you should initialize it in the main activity class of your app.
OnCreate() main class
Rox.setup(this);
Rox.setup(this.getApplication());

Create a container class called Flags.java with the following code

This container class is where we will define all of our feature flags.

import io.rollout.configuration.RoxContainer;
import io.rollout.flags.RoxFlag;

// Create Roxflag in the Flags container class
public class Flags implements RoxContainer {
  //Define the feature flags
    public RoxFlag enableTutorial = new RoxFlag(false),
  public RoxVariant titleColors = new RoxVariant("White", new String[] {"White", "Blue", "Green", "Yellow"})

}

Add the following lines of code to your application

import io.rollout.android.Rox;

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

    //Initialize Flag container class that we created earlier
    Flags flags = new Flags();

    // Register the flags container
    Rox.register("", flags);

    // Setup the key
    Rox.setup(this);

    // This can also be done in the MainActivity
    // if your app doesn't extends the Application class

    // Boolean flag example
    if (flags.enableTutorial.isEnabled()) {
      // TODO:  Put your code here that needs to be gated
    }
    // Multivariate Flag
    if (flags.titleColors.value() == "Blue") {
      Log.i(tag, "Title color is blue");
    } else if (Flags.titleColors.value() == "Green") {
      Log.i(tag, "Title color is green");
    } else if (Flags.titleColors.value() == "Yellow") {
      Log.i(tag, "Title color is yellow");
    } else if (Flags.titleColors.value() == "White") {
      Log.i(tag, "Title color is white");
    }
  }
}

Container class registration and environment key setup

  • You cannot call Rox.setup() twice in the same runtime.

Run your application

Running the application

The flag name is automatically added to the CloudBees Feature Management dashboard after running the application.