Flutter Android error with --release: could not find and invoke the GeneratedPluginRegistrant

Viewed 922

My Flutter app is showing a blank white screen with the following errors when building a signed --release version to run on a physical device:

W/FlutterActivity(24374): Tried to automatically register plugins with FlutterEngine (io.flutter.embedding.engine.a@10d90e5) but could not find and invoke the GeneratedPluginRegistrant.
E/flutter (24374): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: MissingPluginException(No implementation found for method getAll on channel plugins.flutter.io/shared_preferences)

Everything works fine when running in debug.

These are what my various files look like:

MainActivity.kt

package my.app.id

import io.flutter.embedding.android.FlutterActivity

class MainActivity: FlutterActivity() {
}

Application.kt

This was done done because firebase messaging wasnt working, and recommened everywhere online, and fixed my problems, in debug mode at least.

package my.app.id

import io.flutter.app.FlutterApplication
import io.flutter.plugin.common.PluginRegistry
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback
import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService

class Application : FlutterApplication(), PluginRegistrantCallback {

  override fun onCreate() {
    super.onCreate()
    FlutterFirebaseMessagingService.setPluginRegistrant(this);
  }

  override fun registerWith(registry: PluginRegistry) {
    FirebaseCloudMessagingPluginRegistrant.registerWith(registry)
  }
}

FirebaseCloudMessagingPluginRegistrant.kt

package my.app.id

import io.flutter.plugin.common.PluginRegistry
import io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin

class FirebaseCloudMessagingPluginRegistrant {
  companion object {
    fun registerWith(registry: PluginRegistry) {
      if (alreadyRegisteredWith(registry)) {
        return;
      }
      FirebaseMessagingPlugin.registerWith(registry.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"))
    }

    fun alreadyRegisteredWith(registry: PluginRegistry): Boolean {
      val key = FirebaseCloudMessagingPluginRegistrant::class.java.name
      if (registry.hasPlugin(key)) {
        return true
      }
      registry.registrarFor(key)
      return false
    }
  }
}

AndroidManifest.xml (Parts of it)

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

    <application
        android:name=".Application"
        android:label="@string/app_name"
        android:icon="@mipmap/ic_launcher">
        <activity
            android:name=".MainActivity"

        ...

          <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>

            <intent-filter>
                <action android:name="FLUTTER_NOTIFICATION_CLICK" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
...

        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />

build.gradle


defaultConfig {
    applicationId "my.app.id"
    minSdkVersion 21
    targetSdkVersion 28
    versionCode flutterVersionCode.toInteger()
    versionName flutterVersionName
    multiDexEnabled true
  }

  ...

  buildTypes {
    release {
      minifyEnabled true
    }
  }
 ...

dependencies {
  implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version'
  implementation 'com.google.firebase:firebase-messaging:20.2.3'
  implementation 'com.google.firebase:firebase-auth:19.3.2'
}

I've tried everything I know of to figure this out but can't. Im here to give any more info needed, thanks for the help!

0 Answers
Related