Download PDF
Download page Android アプリケーションの手動インストゥルメント化.
Android アプリケーションの手動インストゥルメント化
On this page:
Related pages:
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:4.5.+
を使用します。
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
classpath 'com.appdynamics:appdynamics-gradle-plugin:4.5.+' // this line added for AppDynamics
}
}
allprojects {
repositories {
jcenter()
}
}
プラグインのアクティブ化
モジュールレベル 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 アプリケーションのインストゥルメント化
アプリケーションの構築が完了したら、次の手順を実行します。
アプリケーションキーの取得
After you completed the Getting Started Wizard, you were given an EUM App Key. このキーは、ソースコードを変更するときに必要になります。場合によっては、複数のモバイルアプリケーションが同じキーを共有できます。
[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 Server を使用している場合は、実装の詳細について、「オンプレミス展開用の iOS エージェントの構成(オプション)」を参照してください)。アメリカ地域
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()); ... }
JAVAEMEA
import 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()); ... }
JAVAAPAC
import 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 のインストールと更新のプロセスは同じです。