title: Flutter firebase_message plugin setup errors
body: <p>I wanted to try out cloud messaging in my Flutter application, but I always run into errors, and I have not found a solution yet. I followed the steps stated here: <a href="https://github.com/FirebaseExtended/flutterfire/tree/master/packages/firebase_messaging" rel="noreferrer">firebase_messaging</a> </p>
  
  <p>If I follow the steps except the optional part with creating an Application.java file for background messages, and I send a test message from Firebase to the launched application, I get this error:</p>
  
  <pre><code>java.lang.RuntimeException: Unable to create service io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService: java.lang.RuntimeException: PluginRegistrantCallback is not set.
     at android.app.ActivityThread.handleCreateService(ActivityThread.java:3577)
     at android.app.ActivityThread.access$1400(ActivityThread.java:200)
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1689)
     at android.os.Handler.dispatchMessage(Handler.java:106)
     at android.os.Looper.loop(Looper.java:201)
     at android.app.ActivityThread.main(ActivityThread.java:6806)
     at java.lang.reflect.Method.invoke(Native Method)
     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
  E/AndroidRuntime(29468): Caused by: java.lang.RuntimeException: PluginRegistrantCallback is not set.
     at io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService.startBackgroundIsolate(FlutterFirebaseMessagingService.java:157)
     at io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService.onCreate(FlutterFirebaseMessagingService.java:77)
     at android.app.ActivityThread.handleCreateService(ActivityThread.java:3565)
  </code></pre>
  
  <p>For me it seems like that the optional part is needed too, but when I do that I get errors when the app opens. After the errors the app still runs, and if I send a test message from Firebase the app receives it succesfully. Later it doesn't even receives the message, but thows the same errors.</p>
  
  <pre><code>java.lang.NullPointerException: Attempt to invoke virtual method 'android.app.Application android.app.Activity.getApplication()' on a null object reference
     at com.github.adee42.keyboardvisibility.KeyboardVisibilityPlugin.registerWith(KeyboardVisibilityPlugin.java:107)
     at io.flutter.plugins.GeneratedPluginRegistrant.registerWith(GeneratedPluginRegistrant.java:22)
     at io.flutter.plugins.Application.registerWith(Application.java:18)
     at io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService.startBackgroundIsolate(FlutterFirebaseMessagingService.java:164)
     at io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin.onMethodCall(FirebaseMessagingPlugin.java:133)
     at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:222)
     at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:96)
     at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:656)
     at android.os.MessageQueue.nativePollOnce(Native Method)
     at android.os.MessageQueue.next(MessageQueue.java:326)
     at android.os.Looper.loop(Looper.java:165)
     at android.app.ActivityThread.main(ActivityThread.java:6806)
     at java.lang.reflect.Method.invoke(Native Method)
     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
  
  [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: PlatformException(error, Attempt to invoke virtual method 'android.app.Application android.app.Activity.getApplication()' on a null object reference, null)
      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:569:7)
      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:316:33)
      &lt;asynchronous suspension&gt;
      FirebaseMessaging.configure (package:firebase_messaging/firebase_messaging.dart:118:16)
      main (package:vonatles/main.dart:18:22)
      _AsyncAwaitCompleter.start (dart:async-patch/async_patch.dart:43:6)
      main (package:vonatles/main.dart:12:10)
      _runMainZoned.&lt;anonymous closure&gt;.&lt;anonymous closure&gt; (dart:ui/hooks.dart:229:25)
      _rootRun (dart:async/zone.dart:1124:13)
      _CustomZone.run (dart:async/zone.dart:1021:19)
      _runZoned (dart:async/zone.dart:1516:10)
      runZoned (dart:async/zone.dart:1500:12)
      _runMainZoned.&lt;anonymous closure&gt; (dart:ui/hooks.dart:221:5)
      _startIsolate.&lt;anonymous closure&gt; (dart:isolate-patch/isolate_patch.dart:305:19)
      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:172:12)
  </code></pre>
  
  <p><strong>Versions:</strong>  </p>
  
  <pre><code>firebase_core: ^0.4.0+1  
  firebase_database: 3.0.7  
  firebase_messaging: 5.1.5 
  
  classpath 'com.android.tools.build:gradle:3.3.0'  
  classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.0"  
  classpath 'com.google.gms:google-services:4.3.0'  
  </code></pre>
  
  <p>In the Flutter main function I have this:</p>
  
  <pre><code>final FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
  
  _firebaseMessaging.configure(
    onMessage: (Map&lt;String, dynamic&gt; message) async {
      print("onMessage: $message");
    },
    onLaunch: (Map&lt;String, dynamic&gt; message) async {
      print("onLaunch: $message");
    },
    onResume: (Map&lt;String, dynamic&gt; message) async {
      print("onResume: $message");
    },
  );
  </code></pre>
  
  <p>The Application.java code:</p>
  
  <pre><code>package io.flutter.plugins;
  
   import io.flutter.app.FlutterApplication;
   import io.flutter.plugin.common.PluginRegistry;
   import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback;
   import io.flutter.plugins.GeneratedPluginRegistrant;
   import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService;
  
   public class Application extends FlutterApplication implements PluginRegistrantCallback {
     @Override
     public void onCreate() {
       super.onCreate();
       FlutterFirebaseMessagingService.setPluginRegistrant(this);
     }
  
     @Override
     public void registerWith(PluginRegistry registry) {
       GeneratedPluginRegistrant.registerWith(registry);
     }
   }
  </code></pre>
  
  <p>My android main directory:  </p>
  
  <pre><code>-main  
    -java  
      -io.flutter.plugins  
        Apllication.java  
        GeneratedPluginRegistrant.java  
    -kotlin  
      -my.package.name  
        MainActivity.kt
  </code></pre>
  
  <p>AndroidManifest:</p>
  
  <pre><code>&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="my.package.name"&gt;
      &lt;application
          android:name="io.flutter.plugins.Application"
          android:label="mylabel"
          android:icon="@mipmap/ic_launcher"&gt;
          &lt;activity
              android:name=".MainActivity"
              ...
              &lt;intent-filter&gt;
                  &lt;action android:name="FLUTTER_NOTIFICATION_CLICK" /&gt;
                  &lt;category android:name="android.intent.category.DEFAULT" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
      &lt;/application&gt;
  &lt;/manifest&gt;
  </code></pre>