Flutter二维码阅读器触发MissingPluginException问题求助
Hey there, that MissingPluginException(No implementation found for method readQRCode on channel qrcode_reader) error is a common sign that the native Android side of the plugin isn't properly connected to your Flutter code. Let's walk through actionable fixes tailored to your setup:
Step 1: Reset your build environment
Flutter's auto-linking can sometimes glitch, especially with older devices. Try these steps to clear cached data and re-establish the plugin connection:
- Run
flutter cleanin your project root to delete cached build files - Delete the
buildfolder inside your project'sandroiddirectory - Run
flutter pub getto re-install all dependencies - Do a full app restart (not hot reload/restart)—hot reload won't apply changes to native plugin code
Step 2: Verify camera permissions
QR scanning requires camera access, so double-check your android/app/src/main/AndroidManifest.xml includes these permissions:
<uses-permission android:name="android.permission.CAMERA" /> <uses-feature android:name="android.hardware.camera" /> <uses-feature android:name="android.hardware.camera.autofocus" />
For Android 6+, you also need to request runtime camera permission before triggering the scan. Ensure your code prompts the user for camera access before calling QRCodeReader.scan().
Step 3: Manually register the plugin (for older Flutter versions)
If you're using a Flutter version before 1.20 (when auto-linking was introduced), you'll need to manually register the plugin in your Android activity:
For Java:
Open android/app/src/main/java/[your-package-name]/MainActivity.java and add:
import com.github.adee42.qrcodereader.QRCodeReaderPlugin; @Override public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) { super.configureFlutterEngine(flutterEngine); QRCodeReaderPlugin.registerWith(flutterEngine.getDartExecutor().getBinaryMessenger()); }
For Kotlin:
Open android/app/src/main/kotlin/[your-package-name]/MainActivity.kt and add:
import com.github.adee42.qrcodereader.QRCodeReaderPlugin override fun configureFlutterEngine(flutterEngine: FlutterEngine) { super.configureFlutterEngine(flutterEngine) QRCodeReaderPlugin.registerWith(flutterEngine.dartExecutor.binaryMessenger) }
Step 4: Check Android 7-specific compatibility
Android 7 (API 24) has strict rules around foreground context and camera access:
- Ensure your app's
minSdkVersioninandroid/app/build.gradleis set to at least 24 - Never trigger the QR scan from a background service/widget—only call the scan method from a visible, foreground screen
Step 5: Consider a maintained alternative plugin
If the issue persists, the qrcode_reader plugin may not be actively updated for newer Flutter or Android versions. Try switching to a more maintained QR scanning plugin that explicitly supports older Android versions (avoid relying on unmaintained tools to prevent future issues).
内容的提问来源于stack exchange,提问作者J P

