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:
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 'com.yandex.android:mobmetricalib:3.8.0' // Optionally. Play Install Referrer library. implementation 'com.android.installreferrer:installreferrer:1.0' }
Copied to clipboard
Adding the Play Install Referrer library improves quality of install source tracking.
Download the library and add it to the project.
Step 2. Initialize the 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 { @Override public void onCreate() { super.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. YandexMetrica.enableActivityAutoTracking(this); } }
Copied to clipboard
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:
<manifest> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> <application>...</application> </manifest>
Copied to clipboard
ACCESS_COARSE_LOCATION
allows you to track the device's location. Learn more.