π± persistent_device_id
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.
β¨ Features
- π 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
π¦ Installation
Add this to your pubspec.yaml:
dependencies:
persistent_device_id: <latest_version>
Then run:
flutter pub get
π οΈ Usage
Import the package
import 'package:persistent_device_id/persistent_device_id.dart';
Get the device ID
final deviceId = await PersistentDeviceId.getDeviceId();
print("Device ID: $deviceId");
βοΈ Supported Platforms
| Platform | Support |
|---|---|
| Android | β Yes |
| iOS | β Yes |
π§ How It Works
This plugin uses different secure layers per platform to persist a device-unique identifier:
Android
-
Attempts to derive a hardware-based ID from
MediaDrm(API β₯ 18). -
If
MediaDrmis 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
iOS
- Uses the
Keychainto securely store and persist a generated UUID.
β Android Requirements
- minSdkVersion: 21
- compileSdkVersion: 34
- No special permissions needed
π§ Limitations
MediaDrmonly available on Android API β₯ 18- On some custom or rooted ROMs,
MediaDrmmay 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
π Example
Clone the repository and run the example app:
cd example
flutter run
π License
MIT License. Β© 2025 Mael Toukap.
πββοΈ Contributing
Contributions are welcome! Please open an issue or submit a pull request on GitHub