How to obatin OAID


{primary} Not all apps distributed in China are required to integrate an OAID SDK. OAID is only necessary if your app has specific needs, such as device-level analytics, advertising attribution, or integration with marketing APIs that rely on device identifiers.

OAID and Android_CN_OAID library

OAID (Open Anonymous Device Identifier) is a standard device identifier developed by the Mobile Security Alliance (MSA) in China. It provides a privacy-compliant way to identify devices without using hardware identifiers like IMEI.

Normally, developers must integrate the MSA SDK and complete certification to use OAID. To simplify this process, we introduce a third-party library Android_CN_OAID that enables OAID access without using the MSA SDK or undergoing certification, making it easier for developers outside China to support OAID in their apps.

  • GitHub: https://github.com/gzu-liyujiang/Android_CN_OAID
  • JavaDoc: https://gzu-liyujiang.github.io/Android_CN_OAID

Supported Manufacturers

The Android_CN_OAID library supports Android devices from Chinese brands released after 2019.

Manufacturer/Brand System/Framework
Huawei HMS Core 2.6.2+, Google Play Service 4.0+
Honor Magic UI 4/5/6, MagicOS 7.0+, Google Play Service 4.0+
Xiaomi, Redmi, BlackShark MIUI 10.2+, Google Play Service 4.0+
Vivo, IQOO Funtouch OS 9+, OriginOS 1.0+, Google Play Service 4.0+
Oppo, Realme ColorOS 7.0+, Google Play Service 4.0+
Samsung Android 10+, Google Play Service 4.0+
Lenovo ZUI 11.4+, Google Play Service 4.0+
Asus Android 10+, Google Play Service 4.0+
Meizu Android 10+, Google Play Service 4.0+
OnePlus Android 10+, Google Play Service 4.0+
Nubia Android 10+, Google Play Service 4.0+
Coolpad CoolOS, Google Play Service 4.0+
... ...

Integration Steps

Dependency Configuration

If your project uses Gradle version 7.0 or below, add the following to your build.gradle file:

allprojects {
    repositories {
        // JitPack repository
        maven { url 'https://jitpack.io' }
    }
}

For Gradle 7.0 or above, add the following to your settings.gradle file:

dependencyResolutionManagement {
    repositories {
        // JitPack repository
        maven { url 'https://jitpack.io' }
    }
}

Then, use the following dependency:

dependencies {
    implementation 'com.github.gzu-liyujiang:Android_CN_OAID:4.2.12'
}

Notes

  • If you need to use both the Android_CN_OAID and MSA SDKs simultaneously, you can refer to the configuration below.
dependencies {
    implementation('com.github.gzu-liyujiang:Android_CN_OAID:4.2.12') {
        // If you use a newer version of MSA SDK, you may need to exclude the Huawei SDK:
        // exclude group: 'com.huawei.hms', module: 'ads-identifier'
        // Similarly for Honor SDK:
        // exclude group: 'com.hihonor.mcs', module: 'ads-identifier'
    }
}

// If the Huawei Ads Identifier SDK fails to download or compile, consider adding the following configuration in your build.gradle:
// repositories { maven { url 'https://developer.huawei.com/repo' } }
// runtimeOnly "com.huawei.hms:ads-identifier:3.4.62.300"
// 
// Similarly, for the Honor Ads Identifier SDK:
// repositories { maven { url 'https://developer.hihonor.com/repo' } }
// runtimeOnly "com.hihonor.mcs:ads-identifier:1.0.2.301"
  • The library includes permissions like READ_PHONE_STATE, WRITE_SETTINGS, and WRITE_EXTERNAL_STORAGE for compatibility with older Android versions.
  • To protect user privacy, if your project doesn't need IMEI or GUID, you can remove related permissions from AndroidManifest.xml:
<manifest>
    <uses-permission android:name="android.permission.READ_PHONE_STATE" tools:node="remove" />
    <uses-permission android:name="android.permission.WRITE_SETTINGS" tools:node="remove" />
</manifest>

Code Examples

To obtain multiple possible device identifiers, and combine them with a server-side Byzantine Fault Tolerance method for a reliable and stable unique identifier:

  • Step 1 (Optional, for pre-fetching OAID via getClientId()):
// Initialize in Application#onCreate, ensure app complies with privacy policy
@Override
public void onCreate() {
    super.onCreate();
    if (privacyPolicyAgreed) {
        DeviceIdentifier.register(this);
    }
}
  • Step 2:

We recommend using the asynchronous method to get the OAID:

// Check if OAID/AAID is supported
DeviceID.supportedOAID(this);

// Get OAID/AAID asynchronously
DeviceID.getOAID(this, new IGetter() {
    @Override
    public void onOAIDGetComplete(String result) {
        // Different manufacturers have different OAID/AAID formats.
    }

    @Override
    public void onOAIDGetError(Exception error) {
        // OAID/AAID retrieval failed
    }
});

// Get OAID/AAID synchronously
DeviceIdentifier.getOAID(this);

Proguard Rules

This library includes consumer-rules.pro with rules that prevent obfuscation of vendor-specific interfaces and classes. No additional configuration is required when using the library via remote dependencies:

# Proguard rules for this library (note: "repeackage" is a historical typo)
-keep class repeackage.com.uodis.opendevice.aidl.** { *; }
-keep interface repeackage.com.uodis.opendevice.aidl.** { *; }
-keep class repeackage.com.asus.msa.SupplementaryDID.** { *; }
-keep interface repeackage.com.asus.msa.SupplementaryDID.** { *; }
-keep class repeackage.com.bun.lib.** { *; }
-keep interface repeackage.com.bun.lib.** { *; }
-keep class repeackage.com.heytap.openid.** { *; }
-keep interface repeackage.com.heytap.openid.** { *; }
-keep class repeackage.com.samsung.android.deviceidservice.** { *; }
-keep interface repeackage.com.samsung.android.deviceidservice.** { *; }
-keep class repeackage.com.zui.deviceidservice.** { *; }
-keep interface repeackage.com.zui.deviceidservice.** { *; }
-keep class repeackage.com.coolpad.deviceidsupport.** { *; }
-keep interface repeackage.com.coolpad.deviceidsupport.** { *; }
-keep class repeackage.com.android.creator.** { *; }
-keep interface repeackage.com.android.creator.** { *; }
-keep class repeackage.com.google.android.gms.ads.identifier.internal.** { *; }
-keep interface repeackage.com.google.android.gms.ads.identifier.internal.* { *; }
-keep class repeackage.com.oplus.stdid.** {*; }
-keep interface repeackage.com.oplus.stdid.** {*; }
-keep class com.huawei.hms.ads.** {*; }
-keep interface com.huawei.hms.ads.** {*; }
-keep class com.hihonor.ads.** {*; }
-keep interface com.hihonor.ads.** {*; }
-keep class repeackage.com.qiku.id.** { *; }
-keep interface repeackage.com.qiku.id.** { *; }
# ... other rules

Contact Us

Feel free to contact us at [email protected] when you need any help.