Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tylergaw/f38cedac83a5b8ea77c966718c44bced to your computer and use it in GitHub Desktop.
Save tylergaw/f38cedac83a5b8ea77c966718c44bced to your computer and use it in GitHub Desktop.

Example of a MainApplication.java multidex app

This goes together with the reset of the steps in https://developer.android.com/studio/build/multidex.html

This is our MainApplication.java without all the third party packages we import and use.

The key things are to import the class:

import android.support.multidex.MultiDexApplication;

and extend it:

public class MainApplication extends MultiDexApplication implements ReactApplication

You can remove the import android.app.Application; line from the default react cli init

package com.streetcred.mapnyc;

import android.support.multidex.MultiDexApplication;

import com.facebook.react.ReactApplication;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;

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

public class MainApplication extends MultiDexApplication implements ReactApplication {
  private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
    @Override
    public boolean getUseDeveloperSupport() {
      return BuildConfig.DEBUG;
    }

    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage()
      );
    }

    @Override
    protected String getJSMainModuleName() {
      return "index";
    }
  };

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

  @Override
  public void onCreate() {
    super.onCreate();
    SoLoader.init(this, /* native exopackage */ false);
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment