title: Firebase C++ Messaging Crashing on Startup
body: <p>So, I'm trying to use the Firebase c++ library in my Unreal project, but I'm getting some very consistent crashes: it crashes the first time I run it after a new uninstalling it, and works fine afterwards</p>
  
  <p>Here's the stack trace I've got from firebase crash logging:</p>
  
  <blockquote>
    <p>E/art     ( 7271): No implementation found for void com.google.firebase.messaging.cpp.RegistrationIntentService.nativeOnTokenReceived(java.lang.String) (tried Java_com_google_firebase_messaging_cpp_RegistrationIntentService_nativeOnTokenReceived and Java_com_google_firebase_messaging_cpp_RegistrationIntentService_nativeOnTokenReceived__Ljava_lang_String_2)</p>
    
    <p>E/UncaughtException( 7271): </p>
    
    <p>E/UncaughtException( 7271): java.lang.UnsatisfiedLinkError: No implementation found for void com.google.firebase.messaging.cpp.RegistrationIntentService.nativeOnTokenReceived(java.lang.String) (tried Java_com_google_firebase_messaging_cpp_RegistrationIntentService_nativeOnTokenReceived and Java_com_google_firebase_messaging_cpp_RegistrationIntentService_nativeOnTokenReceived__Ljava_lang_String_2)</p>
    
    <p>E/UncaughtException( 7271):    at com.google.firebase.messaging.cpp.RegistrationIntentService.nativeOnTokenReceived(Native Method)</p>
    
    <p>E/UncaughtException( 7271):    at com.google.firebase.messaging.cpp.RegistrationIntentService.onHandleIntent(RegistrationIntentService.java:31)</p>
    
    <p>E/UncaughtException( 7271):    at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)</p>
    
    <p>E/UncaughtException( 7271):    at android.os.Handler.dispatchMessage(Handler.java:102)</p>
    
    <p>E/UncaughtException( 7271):    at android.os.Looper.loop(Looper.java:145)</p>
    
    <p>E/UncaughtException( 7271):    at android.os.HandlerThread.run(HandlerThread.java:61)</p>
  </blockquote>
  
  <p>It says there's no implementation for nativeOnTokenReceived, but it is implemented in the firebase c++ sdk library.
  The crash happens when RegistrationIntentService is sent an intent from FcmInstanceIDListenerService, which happens when firebase gives a new token, which always happens on app startup after reinstalling it or clearing it's app data (I'm not sure if it's possible to make it happen at a different time than startup).</p>
  
  <p>However, RegistrationIntentService has onHandleIntent activated, and calls nativeOnTokenReceived without any problems when my c++ listener class is initialized, during the course of the app. Does anybody know what might be causing this crash?</p>
  
  <p>It might be relavent that Unreal's build process packages the static .a libraries from the sdk into a single .so before using ndk-build.</p>
  
  <p>Here's the code for RegistrationIntentService and FcmInstanceIDListenerService extracted from the sdk's libmessaging_java.jar</p>
  
  <pre><code>FcmInstanceIDListenerService.java
      package com.google.firebase.messaging.cpp;
  
       import android.content.Intent;
       import com.google.firebase.iid.FirebaseInstanceIdService;
  
       public class FcmInstanceIDListenerService
         extends FirebaseInstanceIdService
       {
         public void onTokenRefresh()
        {
          Intent intent = new Intent(this, RegistrationIntentService.class);
           startService(intent);
         }
       }
  
  RegistrationIntentService.java
      package com.google.firebase.messaging.cpp;
  
      import android.app.IntentService;
      import android.content.Intent;
      import com.google.firebase.iid.FirebaseInstanceId;
  
      public class RegistrationIntentService
         extends IntentService
       {
         private static final String TAG = "FirebaseRegService";
  
         public RegistrationIntentService()
         {
           super("FirebaseRegService");
         }
  
         protected void onHandleIntent(Intent intent)
         {
           DebugLogging.log("FirebaseRegService", String.format("onHandleIntent token=%s", new Object[] {
             FirebaseInstanceId.getInstance().getToken() }));
           String token = FirebaseInstanceId.getInstance().getToken();
           if (token != null) {
             nativeOnTokenReceived(token);
           }
         }
  
         private static native void nativeOnTokenReceived(String paramString);
       }
  </code></pre>