React Native Publishing an Android App

How to fix com.myapp.MainApplication cannot be cast to com.facebook.react.ReactApplication

To fix this issue, thats happening when using react-native-push-notification package with Expokit, you will need to go into your android/src/main/java/host/exp/exponent and open up the MainApplication.java file. The file needs to be edited and changed, so you avoid any errors with getting push notifications. A sample file looks like this:

package host.exp.exponent;


import com.facebook.react.ReactPackage;

import java.util.Arrays;
import java.util.List;

import expolib_v1.okhttp3.OkHttpClient;

// Needed for `react-native link`
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactApplication;
import com.dieam.reactnativepushnotification.ReactNativePushNotificationPackage;
import com.dooboolab.RNIap.RNIapPackage;

public class MainApplication extends ExpoApplication implements ReactApplication{

  @Override
  public ReactNativeHost getReactNativeHost() {
    return mReactNativeHost;
  }


  public List<ReactPackage> getPackages() {
    return Arrays.<ReactPackage>asList(
            new ReactNativePushNotificationPackage(),
            new RNIapPackage()
    );
  }
  private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {

    @Override
    public boolean getUseDeveloperSupport() {
      return BuildConfig.DEBUG;
    }

    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
              new ReactNativePushNotificationPackage(),
              new RNIapPackage()
      );
    }
  };
  @Override
  public boolean isDebug() {
    return BuildConfig.DEBUG;
  }


  @Override
  public String gcmSenderId() {
    return getString(R.string.gcm_defaultSenderId);
  }

  public static OkHttpClient.Builder okHttpClientBuilder(OkHttpClient.Builder builder) {
    // Customize/override OkHttp client here
    return builder;
  }
}

After making changes so your file looks like this, while adding your own packages in the getPackages() functions, rebuild the app, and push notifications should start working if you changed everything correctly.