Download PDF
Download page Android アプリケーションの手動インストゥルメント化.
Android アプリケーションの手動インストゥルメント化
Android アプリケーションをインストゥルメント化するには、最初に使用しているプラットフォームのアプリケーションを構築してからインストゥルメンテーション コードを追加する必要があります。
開始するには、次の手順を実行します。
Android アプリケーションの構築
アプリケーションを構築するには、ご使用のプラットフォームの手順に従います。
AppDynamics ダウンロードページから AppDynamics Android SDK を取得する場合は、手動ダウンロードを参照してください。
Gradle/Android Studio
Android アプリケーションのビルドを構成するには、次の手順を実行します。
Android エージェントのインストール
Android エージェントをインストールするには、ネイティブ パッケージ システムを使用します。アプリケーションモジュール build.gradle
で、AppDynamics Gradle プラグインのクラスパスをビルドパス依存関係句に追加します。Gradle と Android Tools の間の互換性のために別のバージョンの AppDynamics プラグインを使用する必要がある場合を除き、com.appdynamics:appdynamics-gradle-plugin:20.7.1
を使用します。
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
classpath 'com.android.tools.build:gradle:3.4.1' // 3.4.1 or higher
classpath 'com.appdynamics:appdynamics-gradle-plugin:20.7.1' // this line added for AppDynamics
}
}
allprojects {
repositories {
jcenter()
}
}
Android Gradle プラグイン 3.4.1 以降を使用できない場合は、Android Agent 20.4.0 以前のバージョンを使用する必要があります。
プラグインのアクティブ化
モジュールレベル build.gradle
で、adeum
プラグインを以下の例のように com.android.application
プラグインの直後に追加します。
apply plugin: 'com.android.application'
apply plugin: 'adeum' // this line added for AppDynamics
Apache Maven プロジェクト
アプリケーションが Maven プロジェクトの場合は、次の手順を実行します。
<dependencies>
セクションに次のコードを追加します。<dependency> <groupId>com.appdynamics</groupId> <artifactId>appdynamics-runtime</artifactId> <version>1.0</version> </dependency>
TEXT<plugins>
セクションに次のコードを追加します。<plugin> <groupId>com.appdynamics</groupId> <artifactId>appdynamics-maven-plugin</artifactId> <version>1.0</version> <executions> <execution> <phase>compile</phase> <goals> <goal>adinject</goal> </goals> </execution> </executions> </plugin>
TEXT
Ant/Eclipse
手順については、ナレッジベースの記事「Use Ant to Build Android Apps with the AppDynamics Android SDK」を参照してください。
Android アプリケーションのインストゥルメント化
アプリケーションの構築が完了したら、次の手順を実行します。
アプリケーションキーの取得
Getting Started Wizard を完了すると、EUM アプリケーションキーが付与されます。このキーは、ソースコードを変更するときに必要になります。場合によっては、複数のモバイルアプリケーションが同じキーを共有できます。
Getting Started Wizard を完了したのに EUM アプリケーションキーが付与されない場合は、「アプリケーションキーの取得」を参照してください。
必要な権限の追加
アプリケーションの AndroidManifest.xml
ファイルを開き、次の権限があることを確認します。
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
これらの権限の両方が存在しない場合は、追加します。
ソースの変更
アプリケーションのプライマリアクティビティを定義するソースファイルで、次の import を追加します。
import com.appdynamics.eumagent.runtime.Instrumentation;
JAVAプライマリアクティビティの
onCreate()
メソッドで、上記の手順 2 から EUM アプリケーションキーを渡す次の行を追加します。Instrumentation.start(<EUM_APP_KEY>, getApplicationContext());
JAVAファイルを保存します。
コードは次のようになります。import com.appdynamics.eumagent.runtime.Instrumentation; ... @Override public void onCreate(Bundle savedInstanceState) { Instrumentation.start(<EUM_APP_KEY>, getApplicationContext()); ... }
JAVAメソッド
withCollectorURL
およびwithScreenshotURL
を使用してエージェントを初期化する際にメトリックとスクリーンショットを領域内の SaaS EUM Server およびスクリーンショットサービスにレポートするよう Android エージェントを設定します(オンプレミスの EUM サーバ使用している場合は、実装の詳細について、「エージェント設定のカスタマイズ」を参照してください)。import com.appdynamics.eumagent.runtime.Instrumentation; ... @Override public void onCreate(Bundle savedInstanceState) { Instrumentation.start(AgentConfiguration.builder() .withAppKey("<EUM_APP_KEY>") .withContext(getApplicationContext()) // The default SaaS EUM Server and Screenshot Service are in the Americas, // so you can omit the following settings if you are in the Americas. .withCollectorURL("https://col.eum-appdynamics.com") .withScreenshotURL("https://image.eum-appdynamics.com/") .build()); ... }
JAVAimport com.appdynamics.eumagent.runtime.Instrumentation; ... @Override public void onCreate(Bundle savedInstanceState) { Instrumentation.start(AgentConfiguration.builder() .withAppKey("<EUM_APP_KEY>") .withContext(getApplicationContext()) // Configure the iOS Agent to report the metrics and screenshots to // the SaaS EUM Server in EMEA. .withCollectorURL("https://fra-col.eum-appdynamics.com") .withScreenshotURL("https://fra-image.eum-appdynamics.com/") .build()); ... }
JAVAimport com.appdynamics.eumagent.runtime.Instrumentation; ... @Override public void onCreate(Bundle savedInstanceState) { Instrumentation.start(AgentConfiguration.builder() .withAppKey("<EUM_APP_KEY>") .withContext(getApplicationContext()) // Configure the iOS Agent to report the metrics and screenshots to // the SaaS EUM Server in APAC. .withCollectorURL("https://syd-col.eum-appdynamics.com") .withScreenshotURL("https://syd-image.eum-appdynamics.com/") .build()); ... }
JAVA
インストゥルメンテーションの確認
ビルドと検証の手順については、「Android インストゥルメンテーションの確認」を参照してください。
Android モバイルエージェントのアップグレード
エージェントに新しい機能が追加されるため、アプリケーションで Android SDK をアップグレードする必要があります。
アップグレードする方法は、プラットフォームのビルドファイルを更新するだけです。
最新の Android SDK のインストールと更新のプロセスは同じです。