Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Flutter and app store releases

device_info_plus has no androidId any more, or it comes back null

Your error

The getter 'androidId' isn't defined for the type 'AndroidDeviceInfo'.1 more line it can show

Fix it fast

Most common cause, 1 of 3

device_info_plus 4.1.0 and newer removed the androidId getter

Add the android_id plugin from Flutter Community and read the value through it.

Fix
flutter pub add android_id

// lib/device_id.dart
import 'package:android_id/android_id.dart';

const _androidIdPlugin = AndroidId();

Future<String?> readAndroidId() => _androidIdPlugin.getId();
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

The getter 'androidId' isn't defined for the type 'AndroidDeviceInfo' because device_info_plus removed it in 4.1.0; in 4.0.x it still compiled but always returned null. Add the android_id plugin and call AndroidId().getId(), which returns null off Android. AndroidDeviceInfo.id is the build label, not the Android ID. Applies to device_info_plus 4.1 to 13.3.

  • Applies to device_info_plus 4.1 to 13.3.0, android_id 1.0.0 (Flutter 3.47+) or 0.5.2+1 (Flutter 3.10 to 3.46), Flutter 3.50.1 (Dart 3.14)
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Check which device_info_plus version the app resolves. 4.1.0 and newer have no androidId getter at all; 4.0.x keeps the getter but never fills it.

Run this first
dart pub deps --style=compact | grep -E "device_info_plus|android_id"

Then find the line you see in this list and open its fix:

  1. 1device_info_plus 4.1.0 and newer removed the androidId getterThe analyzer reports The getter 'androidId' isn't defined for the type 'AndroidDeviceInfo'
  2. 2An old lockfile still pins device_info_plus 4.0.xThe code compiles, the deps output shows device_info_plus 4.0.x, and androidId is null on every device
  3. 3The android_id call runs on iOS or webAndroid builds return the ID; the same code gives null on an iPhone, the simulator or Chrome

What does the error look like?

  • The getter 'androidId' isn't defined for the type 'AndroidDeviceInfo'.
  • androidId is always null with device_info_plus 4.0.x

Cause 1 of 3

device_info_plus 4.1.0 and newer removed the androidId getter

You seeThe analyzer reports The getter 'androidId' isn't defined for the type 'AndroidDeviceInfo'

Check

The androidId getter isn't defined because device_info_plus 4.0.0 dropped Android ID support to avoid Google Play policy violations, and 4.1.0 removed the getter itself, pointing to a separate package for the value. Code written for 3.x, or copied from an old answer, no longer compiles on any current release. AndroidDeviceInfo.id looks like a replacement but holds Build.ID, a firmware build label such as a changelist number, not a per-device value.

Check
grep -rn "androidId" lib/

Fix

Add the android_id plugin from Flutter Community and read the value through it. Use the 1.x line on Flutter 3.47 and newer (it relies on AGP 9 built-in Kotlin) and 0.5.2+1 on older Flutter. After adding it, stop the app and rebuild from scratch, which the plugin's README also advises when a MissingPluginException shows up.

Fix
flutter pub add android_id

// lib/device_id.dart
import 'package:android_id/android_id.dart';

const _androidIdPlugin = AndroidId();

Future<String?> readAndroidId() => _androidIdPlugin.getId();

Verify

dart analyze reports no undefined getter, and the value prints as a hexadecimal string on an Android device.

Verify
dart analyze
flutter run

Confirmed by pub.dev

Did this fix it?

Cause 2 of 3

An old lockfile still pins device_info_plus 4.0.x

You seeThe code compiles, the deps output shows device_info_plus 4.0.x, and androidId is null on every device

Check

androidId returning null with no build error is the 4.0.x behaviour: that release removed the Android ID from the plugin's platform channel while the Dart getter stayed, so it can only ever give null. A dependency constraint such as ^4.0.0 together with an old pubspec.lock keeps the app on that release.

Check
grep -n -A4 "device_info_plus:" pubspec.yaml pubspec.lock

Fix

Raise the constraint to a current release, remove the androidId reads, and switch to the android_id plugin from the first cause.

Fix
flutter pub add device_info_plus:^13.3.0
flutter pub add android_id

Verify

The deps output now shows device_info_plus 13.x, and readAndroidId() returns a value on Android.

Verify
dart pub deps --style=compact | grep -E "device_info_plus|android_id"

Confirmed by pub.dev

Did this fix it?

Cause 3 of 3

The android_id call runs on iOS or web

You seeAndroid builds return the ID; the same code gives null on an iPhone, the simulator or Chrome

Check

android_id returns null on every platform except Android, as its README states, so shared code that expects a non-null ID breaks on iOS and web. On iOS the closest value in device_info_plus is IosDeviceInfo.identifierForVendor, which is nullable as well.

Check
grep -rn "getId()" lib/

Fix

Branch on the platform and accept null as a real outcome. Never send a raw Android ID to analytics without the privacy policy that Google Play requires for persistent identifiers.

Fix
import 'dart:io' show Platform;
import 'package:android_id/android_id.dart';
import 'package:device_info_plus/device_info_plus.dart';

Future<String?> readDeviceId() async {
  if (Platform.isAndroid) return const AndroidId().getId();
  if (Platform.isIOS) return (await DeviceInfoPlugin().iosInfo).identifierForVendor;
  return null;
}

Verify

The helper returns a value on Android and iOS, and the code paths for null are covered on web.

Verify
flutter test

Confirmed by pub.dev

Did this fix it?

How do I stop it coming back?

  • Treat the Android ID as scoped, not global: on Android 8.0 and newer it is unique per app-signing key, user and device, so a debug build and the Play-signed release return different values, and a factory reset changes it.
  • Store any identifier your backend relies on (for example a UUID you generate at first launch) instead of depending on a hardware or system ID.
  • Read the changelog of device_info_plus before a major upgrade; several majors removed fields such as androidId, the display metrics and serialNumber.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine on the same stack: TaxiDex, Qist Bazaar, SessionBird.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.