Установка SDK

Узнайте, как скачать и установить SDK для Android.

Прежде чем начать

Для выполнения этих инструкций вам потребуется Android Studio.

Установка SDK для Android

Установите SDK для Android через Gradle или вручную.

Install using Gradle

Рекомендуется

Шаг 1. Объявление репозиториев
In the Project build.gradle file, declare the mavenCentral repository:

// ...
repositories {
   mavenCentral()
}
/// ...

Шаг 2. Добавление зависимостей
In the application build.gradle file, add the latest Android SDK package:

dependencies {
    // Get the latest version from https://mvnrepository.com/artifact/com.appsflyer/af-android-sdk
    implementation 'com.appsflyer:af-android-sdk:<<HERE_LATEST_VERSION>>'
    // For example
    // implementation 'com.appsflyer:af-android-sdk:6.12.1>> 
}

Manual install

  1. В Android Studio переключите структуру папок с Android на Project:
  2. Скачайте последнюю версию SDK для Android и вставьте ее в проект Android в app > libs.
  3. Щелкните правой кнопкой добавленный файл jar и выберите Add As Library (Добавить как библиотеку). При появлении запроса нажмите Refactor (Реструктуризация).

    Если появится предложение записать изменения в git (commit), нажмите OK

    .

Настройка необходимых разрешений

Add the following permissions to AndroidManifest.xml in the manifest section:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package=YOUR_PACKAGE_NAME>

      <uses-permission android:name="android.permission.INTERNET" />
      <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

      ...

</manifest>

The AD_ID permission

In early 2022, Google announced a change to the behavior of Google Play Services and fetching of the Android Advertising ID. According to the announcement, apps targeting Android 13 (API 33) and above must declare a Google Play services normal permission in their AndroidManifest.xml file in order to get access to the device’s Advertising ID.

Starting V6.8.0, the SDK adds the AD_ID permission automatically.

📘

Примечание

  • Если ваше приложение участвует в программе Приложения для всей семьи:
    • If using SDK V6.8.0 and above, you should Revoke the AD_ID permission.
    • If using SDK older than V6.8.0, don't add this permission to your app.
  • Для приложений с целевым уровнем API 32 (Android 12L) и более ранней версии это разрешение не требуется.

Apps that use SDK versions older than V6.8.0 and target Android 13 (API 33) and above must manually include the permission in their AndroidManifest.xml to have access to the Advertising ID:

<uses-permission android:name="com.google.android.gms.permission.AD_ID" />

Отзыв разрешения AD_ID

Согласно Политике Google, приложения для детей не должны передавать рекламный идентификатор.

When using SDK V6.8.0 and above, children apps targeting Android 13 (API 33) and above must prevent the permission from getting merged into their app by adding a revoke declaration to their Manifest:

<uses-permission android:name="com.google.android.gms.permission.AD_ID"
 tools:node="remove"/>

Подробные сведения см. в документации Google Play Services.

Правила ProGuard

Необязательно
If you are using ProGuard and you encounter a warning regarding our AFKeystoreWrapper class, then add the following code to your proguard-rules.pro file:

Правила ProGuard для SDK AppsFlyer

-keep class com.appsflyer.** { *; }

Добавление библиотек рефереров магазинов

SDK AppsFlyer поддерживает несколько библиотек рефереров магазинов. Использование реферера магазина повышает точность атрибуции.

Вам нужно только добавить зависимость реферера, SDK позаботится обо всем остальном.

Google Play Install Referrer

Add the following dependency to your build.gradle:

dependencies {
    // ...
    implementation "com.android.installreferrer:installreferrer:2.2"
}

Правила ProGuard для Google Play Install Referrer

-keep public class com.android.installreferrer.** { *; }

Xiaomi GetApps store referrer

V6.9.0
Add the following dependency to your build.gradle:

dependencies {
  // ...
  implementation "com.miui.referrer:homereferrer:1.0.0.6"
}

Правила ProGuard для рефереров магазина Xiaomi GetApps

-keep public class com.miui.referrer.** {*;}

📘

Примечание

Huawei and Samsung store referrers are supported out-of-the-box starting SDK V6.1.1 and do not require any additional integration.

Известные проблемы

Backup rules

If you add android:fullBackupContent="true" inside the tag in the AndroidManifest.xml, you might get the following error:

Manifest merger failed : Attribute application@fullBackupContent value=(true)

To fix this error, add tools:replace="android:fullBackupContent" in the <application> tag in the AndroidManifest.xml file.

If you have your own backup rules specified (android:fullBackupContent="@xml/my_rules"), in addition to the instructions above, please merge them with AppsFlyer rules manually by adding the following rule:

<full-backup-content>
    ...//your custom rules
    <exclude domain="sharedpref" path="appsflyer-data"/>
</full-backup-content>

Missing resource files

SDK V5
If you are using Android SDK V5 and above, make sure that in the APK file, in addition to the classes.dex and resources files, you also have a com > appsflyer > internal folder with files a- and b- inside.
Note: Before SDK 5.3.0, file names are a. and b.

Проверьте, что у вас есть нужные файлы, открыв ваш пакет APK в Android Studio.

Если этих файлов нет, SDK не может отправлять сетевые запросы на наш сервер, и вам нужно будет обратиться к своему менеджеру по работе с клиентами или в службу поддержки.