You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
final String? androidId = await _androidIdPlugin.getId();
20
20
```
21
21
22
+
### Optional defensive handling
23
+
24
+
Treat registration/runtime failures as `null` by wrapping the call in a `try`/`catch`:
25
+
26
+
```dart
27
+
const _androidIdPlugin = AndroidId();
28
+
29
+
String? androidId;
30
+
try {
31
+
androidId = await _androidIdPlugin.getId();
32
+
} on MissingPluginException {
33
+
print('Failed to get Android ID: MissingPluginException');
34
+
androidId = null;
35
+
} on PlatformException catch (e) {
36
+
print('Failed to get Android ID: ${e.message}');
37
+
androidId = null;
38
+
}
39
+
```
40
+
41
+
**Note:**`getId()` returns `null` on non-Android platforms (iOS, Web, etc.). On Android, it throws `MissingPluginException` if the plugin is not properly registered (see more [below](https://pub.dev/packages/android_id#troubleshooting)).
42
+
22
43
## Important
23
44
24
45
Please note that on `Android 8` and above, the `Android ID` is not unique per device, but also per signing key the app was built with:
@@ -33,7 +54,6 @@ The value may change if a factory reset is performed on the device or if an APK
Before using this plugin in your app, make sure to follow Google Play guidelines.
@@ -45,3 +65,43 @@ For example [here](https://support.google.com/googleplay/android-developer/answe
45
65
Use for non-advertising purposes<br>
46
66
You can use persistent identifiers as long as you have a [privacy policy](https://support.google.com/googleplay/android-developer/answer/9859455) and handle the data in accordance with the [Developer Distribution Agreement](https://play.google.com/about/developer-distribution-agreement.html#use) and all applicable privacy laws in the areas where you make your app available.
47
67
</blockquote>
68
+
69
+
## Troubleshooting
70
+
71
+
If you're experiencing `MissingPluginException`, try these steps in order:
72
+
73
+
1.**Full Rebuild**: Stop the app completely and rebuild from scratch
74
+
```bash
75
+
flutter clean
76
+
flutter pub get
77
+
flutter run
78
+
```
79
+
80
+
2.**Check Flutter Version**: Ensure you're using Flutter 3.10.0 or higher
- Should import: `io.flutter.embedding.android.FlutterActivity`
87
+
- Should NOT import: `io.flutter.app.FlutterActivity` (legacy v1 embedding)
88
+
89
+
If using v1 embedding, migrate to v2 following [this guide](https://github.com/flutter/flutter/blob/main/docs/platforms/android/Upgrading-pre-1.12-Android-projects.md)
90
+
91
+
4.**Check Hot Reload**: Plugin registration happens during cold start. If using hot reload/restart:
92
+
- Stop the app completely
93
+
- Run `flutter run` again (not hot restart)
94
+
95
+
5.**Invalidate Caches**: For Android Studio/IntelliJ:
96
+
- File → Invalidate Caches → Invalidate and Restart
97
+
98
+
6.**Test on Real Device**: If on emulator, try on a physical Android device
99
+
100
+
If none of these work:
101
+
- Search existing GitHub issues for a similar report and add your details there, or open a new issue if you can't find one.
102
+
- Include the following information:
103
+
- Flutter version (`flutter --version`)
104
+
- Output of `flutter doctor -v`
105
+
- Your `pubspec.yaml` dependencies
106
+
- Full error stack trace
107
+
- Whether it happens in a fresh project (`flutter create test_app`)
0 commit comments