expo: ExpoKit (Android) Cannot Link Native Modules
We’ve recently detached from Expo to ExpoKit to give us the ability to use native modules and external react-native libraries that are not supported by Expo. For iOS the detachment process has been smooth but on Android I have yet to be able to link a single module. I’ve traced the issue down to the MainApplication.java currently ExpoKit has the MainReactPackage commented out with the comment “Needed for react-native link”. Because this MainReactPackage() is commented out we are getting the following errors when running ‘react-native link’ on Android. java.lang.IllegalStateException: Application instance isn't a react-application.
I’ve since switched my MainApplication.java as follows.
import com.facebook.react.ReactPackage;
import java.util.Arrays;
import java.util.List;
// Needed for `react-native link`
import com.facebook.react.shell.MainReactPackage;
public class MainApplication extends MultiDexApplication {
// Needed for `react-native link`
public List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
// Add your own packages here!
// TODO: add cool native modules
// Needed for `react-native link`
new MainReactPackage()
);
}
}
But now get the following error on start up.

About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 1
- Comments: 20 (9 by maintainers)
@brentvatne - Sorry for leaving this out here for so long. I was able to solve this issue by using the following code. It works by implementing the ReactApplication interface in MainApplication as a normal
react-native initproject would have it setup. I would love to know if @jesseruder as I wouldn’t consider myself too comfortable with Java code. But this will work for now@brentvatne thanks for the reply! After diving deeper into the subject it appears that the package I am trying to implement (https://github.com/wix/react-native-notifications/blob/master/docs/installation.md) expects the application as an argument. Because the main activity does not implement the ReactApplication interface as mentioned by the comments:
the error
java.lang.IllegalStateException: Application instance isn't a react-applicationis being thrown. I am going to keep plugging away and see if I can get this to work and I will report back. If anyone has any suggestions let me know!@chochihim - Sorry for the late reply been out for the holidays. The issue was during a POC to get push notifications to work and we have since moved on w/o implementing the code above. With that said we plan to make push notifications a feature in the coming weeks which will re-open this issue for us. I’ll be sure to keep you updated on my findings.
@chochihim Sure,
I’ve a similar problem about expokit. After detached 2 different library I tried to link. But NativeModules always empty. Here is my first code;
Then I tried like this;
Testing in js;
That prints
NativeModules1418 undefined undefinedBy the way I created a new project with ‘react-native init’. That works very well. What am I missing? Please help.My package.json;
Hi there!
I investigated this and suspect that the detach template is out of date in SDK23, sorry for the hassle. I haven’t confirmed this with our Android lead yet, but I was able to get a project running with a third party native module by not including the
MainReactPackage()ingetPackages(), as follows:@jesseruder can provide more context when he has time. Let me know if this works for you.