Appfigurate™️
HomeDocumentation
  • Introducing Appfigurate™️ 3
  • Getting Started
    • Getting Started
    • Examples
    • Upgrade guide
      • v1.4.0 to v2.2.0
      • v2.1.1 to v2.2.0
      • v2.2.1 to v3.0.0
      • v3.2.1 to v4.0.0
    • iOS native app integration
      • iOS app extension integration
    • watchOS app integration
      • watchOS app extension integration
    • Android native app integration
    • Mobile Flutter integration
      • Flutter iOS
      • Flutter Android
    • React Native integration
      • iOS native module integration
      • Android native module integration
      • JavaScript integration
    • Third party remote configuration providers
      • Firebase Remote Config
      • Launch Darkly
      • Other third party remote configuration providers
  • Configuration subclasses
    • Supported property types
      • Boolean
      • Integer
      • Float
      • Double
      • Plain String
      • Encrypted String
    • Custom executable actions
    • Slider icon types
  • Additional reading
    • Info.plist options
    • AndroidManifest.xml options
    • Displaying overridden configuration
    • Security
      • Best practice
      • Encryption
      • Export compliance
      • App Store compliance
      • PrivacyInfo.xcprivacy
      • Rotating your private key
  • Automation testing
    • iOS native app automation testing
    • Android native automation testing
  • API
    • iOS and watchOS API
    • Android API
    • Mobile Flutter API
    • React Native API
  • Appfigurate User Guide
    • Introduction
    • Main menu
    • Select app
    • Add app
    • Import app
    • Install example apps
    • Settings
      • Passcode Lock
      • Restore
      • Backup
      • Delete all apps and Settings
      • Analytics
    • Edit app
    • Configure app
    • Permissions
  • Appfigurate SE user guide
    • Introduction
    • Manual encryption
      • ENCRYPTED_STRING macro/function
      • ENCRYPTED_STRING_IOS_WATCHOS macro/function
    • Setup iOS Simulator app
    • Setup Android Emulator app
    • Xcode source editor extension
      • Troubleshooting
    • Real device cloud testing services
      • BrowserStack
  • LEGAL
    • License Agreement
    • Privacy Policy
    • Release History
    • Third party notices
Powered by GitBook
On this page
  • Prerequisites
  • Modify build.gradle
  • Add new app into Appfigurate Emulator
  • Output source code snippets
  • Create nz.co.electricbolt.appfiguratelibrary.Configuration subclass
  • Edit AndroidManifest.xml
  • Test your Android app
  1. Getting Started

Android native app integration

Integrating Appfigurate Library into Android native apps

PreviouswatchOS app extension integrationNextMobile Flutter integration

Last updated 5 months ago

Android native apps can be developed in both Kotlin and Java.

For Mobile Flutter apps, jump to . For React Native apps, jump to .

Prerequisites

You must have the following:

  • Android Studio or IntelliJ.

  • Android SDKs and associated Emulators.

  • AppfigurateSE macOS or Windows app.

  • Appfigurate Emulator app installed into one or more Android Emulators (use the for easy 1 click installation).

  • Your app must have a minimum API level 26 (Android 8.0 Oreo) in order to link Appfigurate Library.

Modify build.gradle

In your app's build.gradle add the following to the dependency section:

implementation 'nz.co.electricbolt:appfiguratelibrary:3.1.0'

Add new app into Appfigurate Emulator

Run Appfigurate in the Android Emulator.

Tap ≡ Add app.

Select app type Android.

Enter a URL scheme that will be used by Appfigurate to launch your app in order to read or apply configuration. The URL scheme must be 4-64 ASCII characters in length and must be unique to your app. e.g. YOUR-APP-URLSCHEME

Tap Add app.

Output source code snippets

In Appfigurate Emulator app, under the KOTLIN/ANDROID LIBRARY INTEGRATION or JAVA/ANDROID LIBRARY INTEGRATION section:

Tap Output implementation then tap Console.

The output will be displayed in Android Studio, under the Logcat tab. Filter the output to application nz.co.electricbolt.appfigurate

Create nz.co.electricbolt.appfiguratelibrary.Configuration subclass

In your app, add a Kotlin class called Configuration.kt

Kotlin Configuration example

package com.yourcompany.yourapp

import nz.co.electricbolt.appfiguratelibrary.annotations.*

public class Configuration extends nz.co.electricbolt.appfiguratelibrary.Configuration {

    @BooleanProperty(description = "Log debug output to console", restart = false)
    var debugLogging = false

    @StringPropertyListEdit(regularExpression = "https://[\\w\\.-]+\\.yourappserver.com/.*",
        description = "Application server url", restart = false, keys = {"Dev", "Prod"},
        values = {"https://dev.yourappserver.com/api", "https://www.yourappserver.com/api"})
    var String? serverURL = null

    override fun allowInvalidSignatures(): Boolean {
        return BuildConfig.DEBUG
    }

    override fun publicKey(): String {
        // 41 36 87 71 0D 05
        return """-----BEGIN PUBLIC KEY-----\n
            MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4TZnKfGeXttN7Rr3eiAZ\n
            ...
            ywIDAQAB\n
            -----END PUBLIC KEY-----\n
            """.trimIndent()
    }

    override fun reset() {
        debugLogging = true
        serverURL = "https://www.yourappserver.com/api"
    }

}

In your app, add a Java class called Configuration.java

Java Configuration example

package com.yourcompany.yourapp;

import nz.co.electricbolt.appfiguratelibrary.annotations.BooleanProperty;
import nz.co.electricbolt.appfiguratelibrary.annotations.StringPropertyListEdit;

public class Configuration extends nz.co.electricbolt.appfiguratelibrary.Configuration {

    @BooleanProperty(description = "Log debug output to console", restart = false)
    boolean debugLogging;

    @StringPropertyListEdit(regularExpression = "https://[\\w\\.-]+\\.yourappserver.com/.*",
        description = "Application server url", restart = false, keys = {"Dev", "Prod"},
        values = {"https://dev.yourappserver.com/api", "https://www.yourappserver.com/api"})
    String serverURL;

    @Override
    public boolean allowInvalidSignatures() {
        return BuildConfig.DEBUG;
    }

    @Override
    public String publicKey() {
        // 41 36 87 71 0D 05
        return "-----BEGIN PUBLIC KEY-----\n"
            + "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4TZnKfGeXttN7Rr3eiAZ\n"
            ...
            + "ywIDAQAB\n"
            + "-----END PUBLIC KEY-----\n";
    }

    @Override
    public void reset() {
        debugLogging = true;
        serverURL = "https://www.yourappserver.com/api";
    }

}

Edit AndroidManifest.xml

AndroidManifest.xml example

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools" package="com.yourcompany.yourapp">

    <application
        ...

        <meta-data
            android:name="APLConfigurationSubclass"
            android:value=".Configuration"/>
        <provider
            android:authorities="YOUR-APP-URLSCHEME"
            android:name="nz.co.electricbolt.appfiguratelibrary.CommandContentProvider"
            android:exported="true">
        </provider>
...        

Test your Android app

To test that you've successfully updated your app to use Appfigurate:

  • Compile and run your app to the Emulator instance.

  • Launch the Appfigurate Emulator app.

  • Tap your applications row. The app's configuration will be read in the background.

Paste the Kotlin implementation file output to the Console in the section above.

Note: your public key output to the Console in the section above will be different to the public key in the following example.

Paste the Java implementation file output to the Console in the section above.

Note: your public key output to the Console in the section above will be different to the public key in the following example.

In your apps AndroidManifest.xml file include the following meta-data and provider sections inside your application section. Replace the text YOUR-APP-URLSCHEME with your own app's URL Scheme - the same value you added in the section above.

Appfigurate's screen will now be displayed. You can now change the debugLogging and serverURL properties. Tap Apply⌄ to apply the configuration to your watchOS app.

Now jump to .

Mobile Flutter integration
React Native integration
AppfigurateSE macOS or Windows app
Configure app
Supported property types
Output source code snippets
Output source code snippets
Output source code snippets
Output source code snippets
Add new app into Appfigurate Emulator