Back to Blog
2026-02-28
9 min read

How I Fixed 'Unresolved Reference: Registrar' While Building Emergency 108 — A Flutter Plugin Migration Story

#Flutter#Android#Plugin Migration#Build Error#Emergency 108#Mobile Development#Debugging#Kotlin

How I Fixed "Unresolved Reference: Registrar" While Building Emergency 108 — A Real-World Flutter Build Crisis


The Real Story Behind This Post

I was building Emergency 108 — a full-stack emergency response system built during a hackathon. The app connects citizens in distress with nearby ambulances, hospitals, and drivers in real time using:

  • Flutter for the mobile frontend
  • Spring Boot for the backend REST API
  • Firebase for push notifications
  • Google Maps for live ambulance tracking
  • WebSockets for real-time location updates

The app had a feature where users could pick emergency contacts directly from their phone's contact list — so that in an SOS situation, their loved ones get instantly notified. A perfectly reasonable feature. I used a Flutter package called fluttercontactpicker to implement it.

Everything worked fine in development. Then I ran flutter build apk to generate the first real build — and the entire thing collapsed with this:

e: Unresolved reference 'Registrar'
e: Unresolved reference 'addActivityResultListener'
e: Unresolved reference 'addRequestPermissionsResultListener'
e: Unresolved reference 'messenger'

FAILURE: Build failed with an exception.
Execution failed for task ':fluttercontactpicker:compileDebugKotlin'
> Compilation error. See log for more details

I hadn't touched any Kotlin files. My Dart code was clean. The feature worked perfectly in the emulator. So what went wrong?

This post explains exactly what happened, why it happens, and how to fix it — so you don't lose hours the way I did.


What Is Flutter V1 vs V2 Embedding?

Flutter originally had a V1 plugin embedding system. Plugins used a class called PluginRegistry.Registrar to register themselves with the Flutter engine:

// OLD Flutter V1 way — now REMOVED
class MyPlugin : PluginRegistry.Plugin {
    companion object {
        fun registerWith(registrar: PluginRegistry.Registrar) {
            // register plugin here
        }
    }
}

Flutter later introduced V2 embedding — a cleaner system using FlutterPlugin interface:

// NEW Flutter V2 way — correct
class MyPlugin : FlutterPlugin {
    override fun onAttachedToEngine(binding: FlutterPlugin.FlutterPluginBinding) {
        // register plugin here
    }
}

In Flutter 3.x, the V1 embedding was permanently removed. PluginRegistry.Registrar no longer exists. Any plugin still using it will not compile — regardless of what you do in your own code.


What Each Error Line Actually Means

Unresolved reference 'Registrar'

→ Plugin is calling PluginRegistry.Registrar — a class removed in Flutter 3.x

Unresolved reference 'addActivityResultListener'
Unresolved reference 'addRequestPermissionsResultListener'

→ Methods that existed on the old Registrar object — also removed

Unresolved reference 'messenger'
Unresolved reference 'activity'
Unresolved reference 'context'

→ Properties on the old V1 Registrar class — gone in V2

Critical point: None of this is in your code. It lives in the plugin's source inside your Pub cache:

C:\Users\<you>\AppData\Local\Pub\Cache\hosted\pub.dev\fluttercontactpicker-4.7.0\android\src\...

How to Identify an Abandoned Plugin

Before fixing anything, verify the plugin is actually maintained:

1. Check pub.dev

Go to pub.dev/packages/fluttercontactpicker. Look for:

  • Last published date — years ago = red flag
  • Dart 3 compatible badge — missing = likely abandoned
  • Pub points — low score = poor maintenance

2. Check GitHub

  • Open issues mentioning Registrar with no response
  • Last commit was years ago
  • Maintainer not responding to PRs

3. Run flutter pub outdated

flutter pub outdated

Verdict on fluttercontactpicker v4.7.0

  • Still using PluginRegistry.Registrar (V1)
  • No update for Flutter V2 compatibility
  • Unmaintained GitHub repo
  • Dead package.

Wrong Fixes — Don't Waste Time

flutter clean then rebuild

Same error. Clean builds don't fix removed APIs.

❌ Adding --no-shrink or --no-tree-shake-icons

Unrelated to compilation errors entirely.

❌ Downgrading Flutter SDK

You'd sacrifice security updates and features for a broken plugin.

❌ Editing plugin source in Pub cache

flutter pub get overwrites your changes every time.


The Real Fix — Replace the Plugin

Step 1 — Find a maintained replacement

| Abandoned | Maintained Replacement | pub.dev | |---|---|---| | fluttercontactpicker | flutter_contacts | pub.dev/packages/flutter_contacts |

Step 2 — Update pubspec.yaml

dependencies:
  # Remove this:
  # fluttercontactpicker: ^4.7.0

  # Add this:
  flutter_contacts: ^1.1.9+2

Step 3 — Add Android Permission in AndroidManifest.xml

<uses-permission android:name="android.permission.READ_CONTACTS" />

Step 4 — Migrate the Dart Code

Old code:

import 'package:fluttercontactpicker/fluttercontactpicker.dart';

final PhoneContact contact = await FlutterContactPicker.pickPhoneContact();
final name = contact.fullName ?? 'Contact';
final number = contact.phoneNumber!.number ?? '';

New code:

import 'package:flutter_contacts/flutter_contacts.dart';

final picked = await FlutterContacts.openExternalPick();
if (picked != null) {
  final full = await FlutterContacts.getContact(
    picked.id,
    withProperties: true,
  );
  final name = full?.displayName ?? 'Contact';
  final number = full?.phones.firstOrNull?.number ?? '';
}

Step 5 — Build

flutter pub get
flutter build apk --debug

Result in the Emergency 108 project:

✓ Built build\app\outputs\flutter-apk\app-debug.apk

What I Learned From Emergency 108

Building Emergency 108 under hackathon time pressure taught me something important: build failures on third-party plugins are more dangerous to your timeline than bugs in your own code — because the error points nowhere near your code, making it hard to even know where to start.

The contact picker was a small feature — maybe 20 lines of Dart. But the broken plugin behind it nearly derailed the entire build pipeline of a system designed to dispatch ambulances in life-threatening situations. That context made the urgency very real.

Going forward on Emergency 108 and any Flutter project: always verify a package is actively maintained before adding it, especially for anything touching native Android/iOS APIs.


How to Avoid This in Future Projects

  • Check pub.dev publish date — prefer packages updated within 12 months
  • Look for Dart 3 compatible and Flutter 3+ badges
  • Prefer packages with 130+ pub points out of 160
  • Run flutter pub outdated periodically
  • Avoid packages with open issues about Registrar and no maintainer response

Key Takeaways

  • Unresolved reference 'Registrar' = plugin uses Flutter's removed V1 API
  • The error is always in the plugin's code, never yours
  • flutter clean and downgrading Flutter are not valid fixes
  • The only real fix is replacing the dead plugin with a maintained one
  • Always vet packages before adding them to production Flutter projects

Exact Error Text (For Search Engines)

Unresolved reference 'Registrar'
Unresolved reference 'addActivityResultListener'
Unresolved reference 'addRequestPermissionsResultListener'
Execution failed for task ':compileDebugKotlin'
Flutter PluginRegistry Registrar removed
Flutter build apk failed abandoned plugin

References


Building Emergency 108 taught me that even a small abandoned plugin can kill your entire build. Always verify package maintenance before adding dependencies.