Android / Android TV / Fire TV SDK installation

2 minute read

Control feature rollout for certain user segments of your application with feature flags. To start using feature management in the platform, follow the instructions below to install the SDK and deploy a feature flag.

These same instructions are available in the platform UI. Select Installation from the left pane to use.

To install the SDK:

  1. Select Feature management  Installation.

  2. Select an Environment from the options, or create an environment by completing the following:

    1. Select CREATE ENVIRONMENT.

    2. Enter an Environment name.

    3. (Optional) Enter a Description.

    4. (Optional) Select Approvers if you want to have a manual approval required before deployment.

    5. (Optional) Enter any Properties you want to associate with the environment. For more information, refer to properties configuration and properties in an environment.

    6. Select SUBMIT.

  3. Select Android or Android TV, Fire TV from the language options.

  4. Select Gradle from the platform type options.

  5. Add the following code for the ROX package to the dependencies block of the build.gradle file in your application:

    compile group: 'io.rollout.rox', name: 'rox-android', version: '5.0.5'
  6. Add the following code to the AndroidManifest.xml file in your application. Be sure to replace <YOUR-SDK-KEY> with your SDK key:

    <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <meta-data android:name="rox.apiKey" android:value="<YOUR-SDK-KEY>" />
    • You must put the uses-permission tag outside the application tag, because it enables internet access for your application.

    • You must put the meta-data tag inside the application tag.

    • Your SDK key is a unique environment identifier. During SDK installation, the SDK key is displayed within the Rox.setup call.

  7. Initialize the SDK by either of the following methods:

    • Add the following code to the onCreate() method of your application class:

      Rox.setup(this);
    • Add the following code to your main application class:

      Rox.setup(this.getApplication());
  8. Define the feature flags in a container class, as in the following code:

    import io.rollout.configuration.RoxContainer; import io.rollout.flags.RoxFlag; import io.rollout.flags.RoxString; // Create the Flags container class public class Flags implements RoxContainer { //Define the feature flags public RoxFlag enableTutorial = new RoxFlag(false), public RoxString titleColors = new RoxString("White", new String[] {"White", "Blue", "Green", "Yellow"}) }
  9. Finish by registering the flag container, setting up the SDK key, and configuring the flags, as in the following code:

    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 extend 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.getValue() == "Blue") { Log.i(tag, "Title color is blue"); } else if (Flags.titleColors.getValue() == "Green") { Log.i(tag, "Title color is green"); } else if (Flags.titleColors.getValue() == "Yellow") { Log.i(tag, "Title color is yellow"); } else if (Flags.titleColors.getValue() == "White") { Log.i(tag, "Title color is white"); } } }
    1 The platform provides the unique SDK key for your environment at the <YOUR-SDK-KEY> location within the Rox.setup call.
  10. Run your application and then select TEST INTEGRATION to confirm a successful connection.

After running the application, flags added in the code are automatically added to your feature flag list.

You have installed an SDK and created flags in your application.

Refer to the SDK reference for more information.