OAID integration
Overview
OAID (Open Anonymous Device Identifier) is a standardized device identifier promoted by the Mobile Security Alliance (MSA) and supported by major Chinese smartphone brands. It is designed as a privacy-compliant alternative to traditional device identifiers like IMEI and MAC address.
Note: Not all apps distributed in China are required to integrate an OAID SDK. OAID is only necessary if your app relies on device-level attribution, analytics, or specific marketing APIs.
Always include OAID usage in your privacy policy and obtain user consent before collecting identifiers.
To simplify integration, this page introduces the open-source library Android_CN_OAID, which allows developers to access OAID without going through MSA SDK certification.
Supported Manufacturers
Android_CN_OAID supports most Android devices from Chinese and international 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 Guide
1. Add JitPack Repository
For Gradle 7.0 or below:
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
For Gradle 7.0+ (settings.gradle):
dependencyResolutionManagement {
repositories {
maven { url 'https://jitpack.io' }
}
}
2. Add Dependency
dependencies {
implementation 'com.github.gzu-liyujiang:Android_CN_OAID:4.2.12'
}
3. Optional: Use with MSA SDK
- 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
, andWRITE_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 Example
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 Configuration
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
If you need help integrating OAID or determining whether it’s required for your app, feel free to contact us.