このページでは、Android ビルドタイプのインストゥルメンテーションを有効または無効にする方法について説明します。 

ビルドタイプのデフォルトのインストゥルメンテーション

release ビルドの場合、自動インストゥルメンテーションはデフォルトで有効になっています。 

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

実行時のインストゥルメンテーションの状態の確認

1 つ以上のビルドでインストゥルメンテーションが無効になっている場合は、実行時にインストゥルメンテーションの確認を無効にする必要があります。インストゥルメンテーションの実行時検証を無効にするように、ビルド設定のブール値フィールドを設定することができます。インストゥルメンテーションのランタイム検証は、デフォルトでオンになっています。メソッド withAutoInstrument を使用すると、オフにできます。

ビルド設定では、ビルドタイプの CHECK_ENABLED フィールドにブール値を設定できます。次の表で、設定値とインストゥルメンテーションの状態、およびアプリケーションのランタイム時の動作について説明します。

構成値インストゥルメンテーションの状態ランタイム動作
true[有効(Enabled)]エージェントは、初期化前にインストゥルメンテーションが有効になっていることを確認します。
無効エージェントは、インストゥルメンテーションが有効ではなく、IllegalState 例外をスローしたことを確認します。
false[有効(Enabled)]エージェントは、インストゥルメンテーションが有効になっているかどうかを確認せずに初期化します。
無効

たとえば、次のビルド設定では、リリースビルドの CHECK_ENABLEDtrue に設定され、デバッグビルドでは false に設定されています。 

インストゥルメンテーション コードの実行前にインストゥルメンテーションが有効になっているかどうかは、debug ビルドのエージェントによって確認されません。一方、release ビルドのアプリケーションコードでは、インストゥルメンテーション コードの実行前に確認されます。

...
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


CHECK_ENABLED の値が true の場合、Android エージェントは、初期化コードの実行前に、インストゥルメンテーションが有効になっていることを確認します。値が false の場合、インストゥルメンテーションが有効になっているかどうかに関係なく、Android エージェントは初期化コードを実行します。

次のインストゥルメンテーション初期化コードは、メソッド withCompileTimeInstrumentationCheck を使用してビルド設定 CHECK_ENABLED の値を確認する方法を示しています。

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