This page describes how to enable and disable instrumentation for Android build types. 

Default Instrumentation for Build Types

For release builds, auto-instrumentation is enabled by default. 

adeum {
...
enabledForDebugBuilds = true // Whether auto-instrumentation is enabled for debug builds, true by default.
	enabledForReleaseBuilds = true // Whether auto-instrumentation is enabled for release builds, true by default.
	webViewCallbackCrashReportingEnabled = false // Auto-instrumentation is enabled for WebChromeClient and WebViewClient
...
}
JAVA

Verify the Instrumentation State at Runtime

If one or more of your builds have disabled instrumentation, you need to disable the instrumentation check at runtime. You can set boolean fields in the build configuration to disable the runtime verification of instrumentation. The runtime verification of instrumentation is on by default. You can turn it off using the method withAutoInstrument.

In the build configuration, you can set a boolean value for the CHECK_ENABLED field for build types. The table below shows the config value, the instrumentation state, and then describes the runtime behavior of your applications.

Config ValueInstrumentation StateRuntime Behavior
trueEnabledThe agent will verify that instrumentation has been enabled before initializing.
DisabledThe agent will verify that the instrumentation has not been enabled and then thrown an IllegalState exception.
falseEnabledThe agent will initialize without checking whether instrumentation has been enabled.
Disabled

For example, in the build configuration below, the field CHECK_ENABLED is set to true for the release build and false for the debug build. 

The agent for the debug build will not verify if instrumentation has been enabled before executing instrumentation code, whereas, the application code for the release build will check before executing the instrumentation code.

...
android {
    // usual stuff
    buildTypes {
    // usual stuff
        release {//these lines added for AppDynamics
            //release based configuration
            // The release build by default is not "debuggable". 
            // The build config "CHECK_ENABLED" will be accessible in the runtime environment.
            // This enables the Android Agent to verify that the instrumentation has been enabled before running the initialization code.
            // If instrumentation has not been enabled, an "IllegalState" exception is thrown.  
            buildConfigField "boolean", "CHECK_ENABLED", "true"
        }
        debug {
            // Setting 'CHECKED_ENABLED' to "false" means the Android Agent will run the initialization code without confirming that
            // instrumentation has been enabled. No exception will be thrown.
            buildConfigField "boolean", "CHECK_ENABLED", "false"
        }
    }
}
...
JAVA


If the value of CHECK_ENABLED is true, the Android Agent will confirm that instrumentation has been enabled before executing the initialization code. If the value is false, the Android Agent executes the initialization code regardless of whether instrumentation has been enabled.

The following instrumentation initialization code shows you how to check the value of the build config CHECK_ENABLED with the method withCompileTimeInstrumentationCheck.

import com.appdynamics.eumagent.runtime.Instrumentation;
...
Instrumentation.start(
        AgentConfiguration config = AgentConfiguration.builder()
            .withAppKey(<EUM_APP_KEY>)
            .withContext(this)
            .withCompileTimeInstrumentationCheck(BuildConfig.CHECK_ENABLED)
            .build();
);
...
JAVA