Empty NativeModules on detached CRNA App

Hi there, i’m facing a problem after ejecting CRNA to Expokit.
I ejected because i needed to implement my own android and ios native modules.
It work on ios but on android i can’t see my module in NativeModules component : object NativeModules is empty.

Here’s my android module :

// Main module
package MBFcmToken;

import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.google.firebase.iid.FirebaseInstanceId;

import java.util.HashMap;
import java.util.Map;

public class MBFcmTokenMainModule extends ReactContextBaseJavaModule {

public MBFcmTokenMainModule(ReactApplicationContext reactContext) {
    super(reactContext);
}

@Override
public String getName() {
    return "MBFcmToken";
}

@Override
public Map<String, Object> getConstants() {
    final Map<String, Object> constants = new HashMap<>();
    String refreshedToken = FirebaseInstanceId.getInstance().getToken();
    constants.put("FCM_Token", refreshedToken);
    return constants;
}

}

// Main Package

package MBFcmToken;

import com.facebook.react.ReactPackage;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.ViewManager;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class MBFcmTokenMainPackage implements ReactPackage {

@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
    List<NativeModule> modules = new ArrayList<>();

    modules.add(new MBFcmTokenMainModule(reactContext));

    return modules;
}

@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
    return Collections.emptyList();
}

}

// And the mainApplication

package host.exp.exponent;

import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;

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

import MBFcmToken.MBFcmTokenMainPackage;

// Needed for react-native link
// import com.facebook.react.ReactApplication;

public class MainApplication extends ExpoApplication {

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

// Needed for react-native link
public List getPackages() {
return Arrays.asList(
// Add your own packages here!
// TODO: add native modules!
new MainReactPackage(),
new MBFcmTokenMainPackage()

    // Needed for `react-native link`
    // new MainReactPackage()
);

}

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

@Override
public boolean shouldUseInternetKernel() {
return BuildVariantConstants.USE_INTERNET_KERNEL;
}
}

I can’t understand the problem.
Thank you forwards.

Hi we finally got it.
In order to make your own module to appear in NativeModules you MUST override OnCreate methode in MainApplication like this :slight_smile:

@Override
public void onCreate() {
super.onCreate();
SoLoader.init(this, /* native exopackage */ false);
AppEventsLogger.activateApp(this);
}

Also don’t call MainReactPackage() in getPackages() but only your module(s).

Hope this will help.

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.