Persistent Device ID Logo

πŸ“± persistent_device_id

A Flutter plugin that provides a unique, persistent, and secure device identifier on Androidβ€”even after uninstalling and reinstalling the app.


✨ Features

  • πŸ”’ Generates a unique ID per device
  • ♻️ Persists across app reinstalls (on Android API β‰₯ 18 with MediaDrm)
  • 🧱 Securely stored using Android Keystore + EncryptedSharedPreferences
  • 🚫 No runtime permissions required
  • πŸ“¦ Simple, asynchronous API

πŸ“¦ Installation

Add this to your pubspec.yaml:

dependencies:
  persistent_device_id: <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 🚧 Not yet (coming soon)

🧠 How It Works

  1. On Android (API β‰₯ 18), the plugin attempts to use MediaDrm to derive a hardware-based identifier.

  2. If MediaDrm is unavailable or fails (e.g. on rooted devices), a fallback UUID is generated once and securely stored using:


βœ… Android Requirements

  • minSdkVersion: 21
  • compileSdkVersion: 34
  • No permissions required

🚧 Limitations

  • MediaDrm is only available on Android API 18 (Jelly Bean 4.3) and above.
  • On some rooted or modified devices, MediaDrm may fail or behave inconsistently.
  • iOS support is currently not available.

πŸ” 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.