Installation and initialization

The SDK for Android is a library in AAR format. The library is available in the Maven repository.

This section describes the steps to enable and initialize AppMetrica SDK:

  1. Step 1. Add the library to your project
  2. Step 2. Initialize the library
  3. Step 3. (Optional) Make changes to AndroidManifest.xml

Step 1. Add the library to your project

If you use Gradle for building the app, set this dependency in the dependencies block in the build.gradle file:

dependencies {
    // AppMetrica SDK.
    implementation ''
    // Optionally. Play Install Referrer library.
    implementation ''
Copied to clipboard

Adding the Play Install Referrer library improves quality of install source tracking.

If you don't use Gradle

Download the library and add it to the project.

Step 2. Initialize the library

Attention. You should take into account some features of the AppMetrica library during initialization. For more information, see Features of the AppMetrica library.

Initialize the library in the app and set up user activity tracking. Extend the Application class and override the onCreate() method as follows:

public class MyApp extends Application {

    public void onCreate() {
        // Creating an extended library configuration.
        YandexMetricaConfig config = YandexMetricaConfig.newConfigBuilder(API_key).build();
        // Initializing the AppMetrica SDK.
        YandexMetrica.activate(getApplicationContext(), config);
        // Automatic tracking of user activity.
Copied to clipboard
What is the API key?

The API key is a unique application identifier that is issued in the AppMetrica web interface during app registration.

Make sure you have entered it correctly.

AppMetrica allows tracking pre-installed apps. To use this feature, you should initialize the library with the extended configuration.

Step 3. (Optional) Make changes to AndroidManifest.xml

For tracking the device location, open the AndroidManifest.xml file and make the following changes before the application element:

    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
Copied to clipboard

ACCESS_COARSE_LOCATION allows you to track the device's location. Learn more.