Example Kotlin Android application for CloudBees Unify feature management

3 minute read

Use this example application to integrate with CloudBees Unify and test feature management. After integrating, observe the application display changes in response to updates you make to flag values in {KPRODUCT}

In the example Kotlin application, the ROX SDK is already set up, and feature flags are already coded in.

Get started with the android-fm-example project

To get started with the android-fm-example project, follow these steps:

  1. Using Git, clone the android-fm-example repository to your local machine:

    git clone git@github.com:cloudbees-io/android-fm-example.git
  2. Build and open the project:

    1. In Android Studio, select File  New  Import Project and open the cloned repository.

    2. If you are using an emulator, start the emulator.

  3. Locate and copy the SDK key:

    1. Navigate to Feature management  Flags.

    2. Select an application.

    3. Select COPY next to the SDK key on the page.

      If you do not see an SDK key:

      1. Navigate to Feature management  Flags.

      2. Select Installation instructions in the upper-right corner.

      3. Follow the installation instructions to complete the installation.

      4. The SDK key will appear once an application is linked to an environment.

      5. Close the installation instructions, and copy the SDK Key.

  4. Reopen your project in Android Studio.

  5. You must add the SDK key to your Cloudbees account: In the AndroidManifest.xml file, replace the <Your Cloudbees SDK Key> with your corresponding API key:

    <meta-data android:name="rox.apiKey" android:value="<Your Cloudbees SDK Key>" />
  6. In Android Studio, select android-studio-run to run the android-fm-example application.

    After running the application, the flags displayed in Feature flags in the example application. are automatically added to your Flags dashboard in CloudBees Unify.

View the imported flags

Now that your application is running:

  1. In CloudBees Unify, select Feature management.

  2. Select your example application to display the available flags as shown in the table below.

    Table 1. Feature flags in the example application.
    Flag name Flag type Description

    showMessage

    Boolean

    Turns the message on or off.

    message

    String

    Sets the message text.

    fontSize

    Number (Int for Python)

    Sets the message font size in pixels. The flag value has the following variations: 12, 16, or 24.

    fontColor

    String

    Sets the message font color. The flag value has the following variations: red, green, or blue.

Apply changes to flags in the UI

  1. Select Feature management.

  2. Select the application.

  3. Select Vertical ellipsis next to the flag you want to configure.

  4. Select Configure.

  5. Select the Environment.

  6. Update a flag value and save your changes.

  7. Set the Configuration status to On.

  8. The updated flag value is reflected in the display of the application.

Use the application with multiple SDK keys

You can run multiple instances of the SDK in a single application, each with its own SDK key and environment. Each instance is fully isolated.

Use multiple SDK instances when you need to:

  • Read or compare feature flags across environments without redeploying

  • Support multi-tenant routing using separate environments

  • Combine server-side and client-side evaluations in one application

To use multiple SDK keys, follow these steps:

  1. Retrieve the SDK keys for the environments you want to use.

  2. Initialize a separate SDK instance for each SDK key.

  3. Decide how your application routes requests to the appropriate instance (for example, by tenant, region, or environment selector).

  4. Perform any required registration, fetch, or streaming setup for each instance, as supported by your SDK.

  5. Evaluate feature flags using the selected SDK instance. Pass a consistent user or context object to ensure accurate targeting.

  6. Tag logs or metrics by SDK instance, and shut down any instances you no longer need.

For more information about using multiple SDK keys, refer to Manage multiple SDK keys in your application.

Documentation reference

Refer to Install the SDK for more information