title: Firebase Cloud Messaging Service Unable to instantiate service FCM.MessagingService
body: <p>I have included Firebase Cloud Messaging Service and push notification service in my app by following official documentation. However, when I receive the message my app crash</p>
  
  <p>However, I cannot receive push notification from my server. The error log says below.</p>
  
  <p><strong>Error Message:</strong></p>
  
  <pre><code>Unable to instantiate service com.abc.myapp.MyFirebaseMessagingService: java.lang.ClassNotFoundException: Didn't find class "com.abc.myapp.MyFirebaseMessagingService" on path: DexPathList[[zip file "/data/app/com.abc.myapp-2/base.apk"],nativeLibraryDirectories=[/data/app/com.abc.myapp-2/lib/arm64, /system/lib64, /vendor/lib64]]
  </code></pre>
  
  <p><strong>Manifest:</strong></p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.abc.myapp"&gt;
  
      &lt;!-- adding internet permission --&gt;
      &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
      &lt;uses-permission android:name="android.permission.READ_PHONE_STATE" /&gt;
      &lt;uses-permission android:name="android.permission.CAMERA" /&gt;
  
      &lt;uses-feature android:name="android.hardware.wifi" /&gt;
      &lt;uses-feature android:name="android.hardware.camera" /&gt;
      &lt;uses-feature android:name="android.hardware.camera.autofocus" /&gt;
  
      &lt;application
          android:allowBackup="true"
          android:icon="@mipmap/ic_launcher"
          android:label="@string/app_name"
          android:roundIcon="@mipmap/ic_launcher_round"
          android:supportsRtl="true"
          android:theme="@style/AppTheme"
          android:usesCleartextTraffic="true"&gt;
          &lt;service
              android:name=".MyFirebaseMessagingService"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="com.google.firebase.MESSAGING_EVENT" /&gt;
              &lt;/intent-filter&gt;
          &lt;/service&gt;
  
          &lt;activity android:name=".QRScanner" /&gt;
          &lt;activity android:name=".ApproveLeaveActivity" /&gt;
          &lt;activity android:name=".AddLeaveActivity" /&gt;
          &lt;activity android:name=".LeaveActivity" /&gt;
          &lt;activity android:name=".CustInParking" /&gt;
          &lt;activity android:name=".SalaryActivity" /&gt;
          &lt;activity android:name=".AttendanceActivityDataHandler" /&gt;
          &lt;activity android:name=".AttendanceActivity" /&gt;
          &lt;activity
              android:name=".LoginActivity"
              android:label="@string/title_activity_login"
              android:windowSoftInputMode="stateHidden" /&gt;
          &lt;activity android:name=".SplashActivity"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
          &lt;activity android:name=".MainActivity"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
  
          &lt;meta-data
              android:name="com.google.firebase.messaging.default_notification_icon"
              android:resource="@drawable/ic_stat_name" /&gt;
  
          &lt;meta-data
              android:name="com.google.firebase.messaging.default_notification_color"
              android:resource="@color/colorAccent" /&gt;
          &lt;meta-data
              android:name="firebase_messaging_auto_init_enabled"
              android:value="ture" /&gt;
          &lt;meta-data
              android:name="firebase_analytics_collection_enabled"
              android:value="true" /&gt;
  
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p><strong>MyFirebaseMessagingService:</strong></p>
  
  <pre><code>    package com.abc.myapp;
  
  import android.app.Notification;
  import android.app.NotificationManager;
  import android.app.PendingIntent;
  import android.app.Service;
  import android.content.Intent;
  import android.media.RingtoneManager;
  import android.os.IBinder;
  import android.util.Log;
  
  import androidx.core.app.NotificationCompat;
  
  import com.google.firebase.iid.FirebaseInstanceId;
  import com.google.firebase.messaging.FirebaseMessaging;
  import com.google.firebase.messaging.FirebaseMessagingService;
  import com.google.firebase.messaging.RemoteMessage;
  
  import static android.content.ContentValues.TAG;
  
  public class MyFirebaseMessagingService extends FirebaseMessagingService {
      @Override
      public void onMessageReceived(RemoteMessage remoteMessage) {
          //showNotification(remoteMessage.getNotification().getBody());
          Log.e(TAG, "From: " + remoteMessage.getFrom());
          Log.e(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
  
      }
      @Override
      public void onNewToken(String token) {
          Log.d(TAG, "Refreshed token: " + token);
  
          // If you want to send messages to this application instance or
          // manage this apps subscriptions on the server side, send the
          // Instance ID token to your app server.
          sendRegistrationToServer(token);
      }
  
      private void sendRegistrationToServer(String token) {
          Log.d("TOKEN ", token);
      }
      public void showNotification(String message){
          PendingIntent pi = PendingIntent.getActivity(this,0, new Intent(this, MainActivity.class),0);
          Notification notification = new NotificationCompat.Builder(this)
                  .setSmallIcon(R.drawable.ic_stat_name)
                  .setContentTitle("Suzuki Islamabad Motors")
                  .setContentText(message)
                  .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
                  .setContentIntent(pi)
                  .setAutoCancel(true)
                  .build();
          NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
          notificationManager.notify(0,notification);
      }
  }
  </code></pre>
  
  <p><strong>Gradle Dependancies:</strong></p>
  
  <pre><code>apply plugin: 'com.google.gms.google-services'
  
  implementation 'com.google.firebase:firebase-analytics:17.2.2'
  implementation 'com.google.firebase:firebase-messaging:20.1.0'
  </code></pre>