UUID generator · Guide

Generate UUID Android: Kotlin and Java on Device

Android exposes `java.util.UUID`, so generating one is a single call. The interesting part is what people usually want it for — a stable device identifier — where the platform rules changed significantly.

Generating one

Java
val id: UUID = java.util.UUID.randomUUID()   // v4
val s: String = id.toString()

randomUUID() uses SecureRandom, so it is suitable for identifiers that must not be guessable. It is a v4, and the JDK on Android has no v7 generator — add java-uuid-generator or uuid-creator if you need time-ordered ids.

A stable install identifier

To identify an installation rather than a moment, generate once and persist:

Java
fun installId(context: Context): String {
    val prefs = context.getSharedPreferences("app", Context.MODE_PRIVATE)
    return prefs.getString("install_id", null) ?: java.util.UUID.randomUUID().toString()
        .also { prefs.edit().putString("install_id", it).apply() }
}

This resets on reinstall or when app data is cleared — which is the intended behaviour, and what Google Play policy expects for a resettable identifier.

What not to use

ANDROID_ID is scoped per app-signing-key and per user since Android 8, and it survives app data clearing, which makes it a persistent identifier subject to policy restrictions.

IMEI, MAC address and serial number are unavailable to normal apps since Android 10. Code that reads them returns a constant placeholder rather than failing, which is why old snippets appear to work while producing the same value on every device.

For advertising use the Advertising ID, which users can reset and opt out of, and never for account identity.

Backup can duplicate your id

Android Auto Backup includes SharedPreferences by default, so restoring a backup onto a second device gives both devices the same install id.

Exclude the key from backup with a backup_rules.xml if the identifier must be unique per device — otherwise expect duplicates in your analytics.

Frequently asked questions

Is UUID.randomUUID secure on Android?

Yes, it uses SecureRandom.

Can I use ANDROID_ID as a device id?

It is scoped per signing key and persists across data clearing, which brings policy constraints. A stored UUID is the recommended approach.

Why do two devices report the same install id?

Auto Backup restored the SharedPreferences file. Exclude the key from backup.

Ready to try it?

Open the free browser-based UUID generator and apply what you just read — no sign-up, runs locally.

Open the UUID generator tool