A Flutter plugin that provides a unique, persistent, and secure device identifier—even after reinstalling the app or resetting the device. Supports Android and iOS using system-level cryptography and secure storage.
- 🔒 Generates a unique and persistent ID per device
- ♻️ Persists across app reinstalls, cache wipes, and even factory resets (when possible)
- 🛡️ Uses MediaDrm, Android Keystore, and EncryptedSharedPreferences on Android
- 🍏 Uses Keychain on iOS
- 🚫 Requires no runtime permissions
- 📦 Simple, asynchronous API
Add this to your pubspec.yaml
:
dependencies:
persistent_device_id: <latest_version>
Then run:
flutter pub get
import 'package:persistent_device_id/persistent_device_id.dart';
final deviceId = await PersistentDeviceId.getDeviceId();
print("Device ID: $deviceId");
Platform | Support |
---|---|
Android | ✅ Yes |
iOS | ✅ Yes |
This plugin uses different secure layers per platform to persist a device-unique identifier:
-
Attempts to derive a hardware-based ID from
MediaDrm
(API ≥ 18). -
If
MediaDrm
is not supported or fails (e.g. on rooted/custom ROM devices), falls back to:- A generated UUID
- Stored in
EncryptedSharedPreferences
- Protected by the
Android Keystore
- Uses the
Keychain
to securely store and persist a generated UUID.
- minSdkVersion: 21
- compileSdkVersion: 34
- No special permissions needed
MediaDrm
only available on Android API ≥ 18- On some custom or rooted ROMs,
MediaDrm
may be unreliable - Factory reset will remove the ID unless hardware-backed
- On iOS, Keychain-based ID may reset if iCloud Keychain is disabled or device is restored without backup
Clone the repository and run the example app:
cd example
flutter run
MIT License. © 2025 Mael Toukap.
Contributions are welcome! Please open an issue or submit a pull request on GitHub