Related pages: |
To instrument Android Applications, you need to first build the application for the platform you are using and then add the instrumentation code.
To get started, follow the instructions below:
To build your application, follow the instructions for your platform:
If you are fetching the |
Complete the following steps to configure the build for your Android application:
Use the native package system to install the Android Agent. In the app module build.gradle
, add the class path of the Gradle Plugin to the build path dependencies clause. For
classpath 'com.appdynamics:appdynamics-gradle-plugin:'
use the latest Android Agent version from the Downloads Portal. However, you can use an older version of the
plugin for compatibility between your Gradle and Android Tools or for other reasons.
If you are unable to use the Android Gradle plugin 3.4.1 or higher, you will have to use the Android Agent 20.4.0 or an earlier version. |
buildscript { repositories { mavenCentral() } 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:<android-agent-version>' // Set to your Android Agent version. } } allprojects { repositories { mavenCentral() } } |
In your module-level build.gradle
, add the adeum
plugin immediately after the com.android.application
plugin, so that it looks similar to the example below:
apply plugin: 'com.android.application' apply plugin: 'adeum' // this line added for AppDynamics |
If your application is a Maven Project:
Add the following code to the <dependencies>
section:
<dependency> <groupId>com.appdynamics</groupId> <artifactId>appdynamics-runtime</artifactId> <version>1.0</version> </dependency> |
Add the following code to the <plugins>
section:
<plugin> <groupId>com.appdynamics</groupId> <artifactId>appdynamics-maven-plugin</artifactId> <version>1.0</version> <executions> <execution> <phase>implementation</phase> <goals> <goal>adinject</goal> </goals> </execution> </executions> </plugin> |
See the Knowledge Base article Use Ant to Build Android Apps with the Cisco AppDynamics Android SDK for instructions.
After you have completed building your application, follow the steps below:
Open your application's AndroidManifest.xml
file and verify that it has these permissions:
<uses-permission android:name="android.permission.INTERNET"></uses-permission> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission> |
If both of these permissions are not present, add them.
To get your EUM App Key in the Controller UI:
Click Add App > Android to open the Getting Started Wizard - Android page.
745px
Click Manual.
Due to |
In the source file that defines your application's primary Activity, add the following import:
import com.appdynamics.eumagent.runtime.Instrumentation; |
In your primary Activity's onCreate()
method, add the following lines, passing in the EUM App Key from Step 2 above:
Instrumentation.start(<EUM_APP_KEY>, getApplicationContext()); |
Save the file. Your code should look something like this:
import com.appdynamics.eumagent.runtime.Instrumentation; ... @Override public void onCreate(Bundle savedInstanceState) { Instrumentation.start(<EUM_APP_KEY>, getApplicationContext()); ... } |
Configure the Android Agent to report metrics and screenshots to the SaaS EUM Server and Screenshot Service in your region when initializing the agent with the methods withCollectorURL
and withScreenshotURL
. (If you are using an on-premises EUM Server, see Customize the Agent Configuration for implementation details.)
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://<your_region>-col.eum-appdynamics.com") .withScreenshotURL("https://<your_region>-image.eum-appdynamics.com/") .build()); ... } |
In your module-level build.gradle
file, add your account information as configurations in the
adeum
snippet. If you complete this step in the Getting Started Wizard, the configurations will populate in the UI code snippet. If you cannot get the EUM App Key from the Getting Started Wizard, see Access Browser Monitoring Configuration.
dependencies { implementation 'com.appdynamics:appdynamics-runtime:<latest version>' // This line is added for Cisco AppDynamics. } adeum { // This section is added for Cisco AppDynamics. account { name '<account name>' licenseKey '<key>' } |
If you are using Android Studio, you need to add a build script block to the top of your project's build.gradle
file:
// project level build.gradle buildscript { dependencies{ classpath("com.appdynamics:appdynamics-gradle-plugin:<latest-version>")} repositories { mavenCentral() } } |
Alternatively, you can use the plugin block and define the resolutionStrategy
block in the settings.gradle
file:
// project level build.gradle plugins{ id 'com.appdynamics.appdynamics-gradle-plugin' version<version> } // settings.gradle repositories{ gradlePluginPortal() mavenCentral() } resolutionStrategy { eachPlugin { plugin -> if (plugin.requested.id.id == "com.appdynamics.appdynamics-gradle-plugin") { useModule("com.appdynamics:appdynamics-gradle-plugin:<latest-version>") } } } |
Build your Android app following the instructions for your build system:
Here is an example of something you would see in your console:
[injector] /=========================================\ [injector] | Cisco AppDynamics BCI Instrumentation summary | [injector] \=========================================/ [injector] [injector] [injector] - Total number of classes visited (#720 classes) [injector] - Total number of classes instrumented (#1 classes) [injector] - Total number of classes failed to instrument (#2 classes) [injector] - Total number of features discovered (#3) [injector] |
Based on the build system you used, verify that the instrumentation was successful:
If you didn't use the -i
flag, check to make sure there is a line in your console output that contains "inject
". If you don't see this information printed in your console, either your project is incorrectly configured or the injector failed to run completely. There is a very detailed log of this process either at <project>/target/appdynamics_eum_android_bci.log
or <module>/target/appdynamics_eum_android_bci.log
.
If you don't see this information printed in your console, either your project is incorrectly configured or the injector failed to run completely. There is a very detailed log of this process either at <project>/target/appdynamics_eum_android_bci.log
or <module>/target/appdynamics_eum_android_bci.log
.
If you don't see this information printed in your console, either your project is incorrectly configured or the injector failed to run completely. There is a very detailed log of this process either at <project>/target/appdynamics_eum_android_bci.log
or <module>/target/appdynamics_eum_android_bci.log
.