Instal SDK

Pelajari cara mengunduh dan menginstal SDK Android.

Disarankan

Get started with our SDK integration wizard

Menginstal SDK Android

Instal SDK Android SDK menggunakan metode pilihan Anda: Melalui Gradle, atau secara manual.

Install using Gradle

Disarankan

Langkah 1: Deklarasikan repositori
In the Project build.gradle file, declare the mavenCentral repository:

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

Langkah 2: Tambahkan dependensi
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. Di Android Studio, ubah struktur folder dari Android ke Proyek:
  2. Unduh SDK Android terbaru dan rekatkan di proyek Android, di bawah app > libs.
  3. Klik kanan jar yang Anda rekatkan dan pilih Add as Library. Saat diminta, klik Refactor.

    Jika diminta untuk menyimpan perubahan ke git, klik OK.

    .

Mengatur hak akses yang diperlukan

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.

📘

Catatan

  • Jika aplikasi Anda termasuk dalam program Dirancang untuk Keluarga:
    • 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.
  • Untuk aplikasi yang menargetkan API level 32 (Android 12L) atau lebih lama, izin ini tidak diperlukan.

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" />

Mencabut izin AD_ID

Menurut Kebijakan Google, aplikasi yang menargetkan anak-anak tidak boleh mengirimkan ID Iklan.

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"/>

Untuk informasi selengkapnya, lihat dokumentasi Layanan Google Play .

Aturan ProGuard

OPSIONAL
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:

Aturan AppsFlyer SDK ProGuard

-keep class com.appsflyer.** { *; }
-keep class kotlin.jvm.internal.** { *; }

Aturan backup

The SDK's AndroidManifest.xml includes rules to opt out of backing up the Shared Preferences data. This is done to avoid retaining the same counters and AppsFlyer ID during reinstallation, thereby preventing the accurate detection of new installs or re-installs.

To merge the SDK backup rules with your app backup rules and to prevent conflicts, perform the following instructions for each use case.

Fix confilict with fullBackupContent=”true”

If you add android:fullBackupContent="true" 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.

Fix conflict with dataExtractionRule=”true”

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

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

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

Fix conflict with allowBackup=”false”

If you add android:allowBackup="false" in the AndroidManifest.xml, you might get the following error:

Error:
	Attribute application@allowBackup value=(false) from AndroidManifest.xml:
	is also present at [com.appsflyer:af-android-sdk:6.14.0] AndroidManifest.xml: value=(true).
	Suggestion: add 'tools:replace="android:allowBackup"' to <application> element at AndroidManifest.xml to override.

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

Merge backup rules in Android 12 and above

If you’re targeting Android 12 and above, and you have your own backup rules specified (android:dataExtractionRules="@xml/my_rules"), in addition to the instructions above, please merge your backup rules with the AppsFlyer rules manually by adding the following rule:

<data-extraction-rules>
    <cloud-backup>
        <exclude domain="sharedpref" path="appsflyer-data"/>
    </cloud-backup>
    <device-transfer>
        <exclude domain="sharedpref" path="appsflyer-data"/>
    </device-transfer>
</data-extraction-rules>

Merge backup rules in Android 11 and below

If you’re also targeting Android 11 and lower, and you have your own backup rules specified (android:fullBackupContent="@xml/my_rules"), in addition to the instructions above, please merge your backup rules with the AppsFlyer rules manually by adding the following rule:

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

Menambahkan pustaka perujuk toko

SDK AppsFlyer mendukung beberapa pustaka perujuk toko. Menggunakan perujuk toko meningkatkan akurasi atribusi.

Anda hanya perlu menambahkan dependensi perujuk, SDK akan menangani sisanya.

Google Play Install Referrer

Add the following dependency to your build.gradle:

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

Aturan ProGuard Install Referrer Google Play

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

Meta Install Referrer

Meta install referrer allows AppsFlyer to receive ad campaign metadata from a device’s local storage.

Meta Install Referrer basic flow

The basic flow of the Meta install referrer mechanism is as follows:

  1. Once the SDK initializes, it uses the app's Facebook App ID to make a request to the Meta Content Provider API, retrieving the stored metadata from the Facebook app.
  2. AppsFlyer SDK sends the install event, along with the attribution data, to the AppsFlyer servers.

Prasyarat

To support the Meta install referrer, the following is required:

  • SDK: Integrate with Android SDK version 6.12.6 or higher.
  • Facebook App Version: Users must have version 428.x.x or above installed on their device.
  • Instagram App Version: Users must have version 296.x.x or above installed on their device.

Configure Meta Install Referrer Support

To enable Meta install referrer support make the Facebook App ID available to the SDK by adding it to the AndroidManifest.xml. This can be done either when integrating the Facebook SDK with the app or when integrating the AppsFlyer SDK with the app.

With Facebook SDK integrated

Refer to Facebook’s official guide to learn how to add the Facebook App ID to AndroidManifest.xml. The SDK will read the Facebook App ID from the meta-data tag.

Without Facebook SDK integration

Include the following tag in AndroidManifest.xml 

<meta-data android:name="com.appsflyer.FacebookApplicationId" android:value="@string/facebook_application_id" />

Include in your strings.xml file:

<string name="facebook_application_id" translatable="false"><YOUR_FACEBOOK_APP_ID></string>

Huawei Install Referrer

Huawei Referrer is supported in SDK v6.14.0 and above.
Due to changes in the Huawei AppGallery store, previous versions of the AppsFlyer SDK are not able to fetch the referrer from the store.

Add the following repository to your Project's build.gradle:

repositories {
    //...
    maven { url 'https://developer.huawei.com/repo/' }
}

Add the following dependency in the app's build.gradle:

dependencies {
    // ...
    implementation 'com.huawei.hms:componentverifysdk:13.3.1.301'
}

If you are using ProGuard, add the following keep rules to your proguard-rules.pro file:

-keep class com.huawei.hms.**{*;}

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"
}

Aturan ProGuard perujuk toko Xiaomi GetApps

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

📘

Catatan

Samsung store referrer is supported out-of-the-box starting SDK V6.1.1 and does not require any additional integration.

Masalah Yang Diketahui

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.

Periksa apakah Anda memiliki file yang diperlukan dengan membuka APK di Android Studio:

Jika file tersebut hilang, SDK tidak dapat membuat permintaan jaringan ke server kami, dan Anda perlu menghubungi CSM atau tim dukungan Anda.

Boot Complete

If your app listens for LOCKED_BOOT_COMPLETED, make sure that all interactions with the SDK are initiated from the launcher activity. This precaution prevents the SDK from crashing when attempting to access SharedPreferences on a device that is still locked.