ExpoKit (Android) Cannot Link Native Modules
See original GitHub issueWe’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.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:20 (4 by maintainers)
Top Results From Across the Web
Ejected Expo app cannot find custom native module in ...
I followed this tutorial to try to implement a custom native Android module, with a few changes due to the layout of an...
Read more >Developing With ExpoKit - Expo Documentation
ExpoKit is an Objective-C and Java library that allows you to use the Expo platform with a native iOS/Android project.
Read more >Troubleshooting React-Native - OneSignal Documentation
Unfortunately you can't have non-Gradle Java modules and Android-Gradle modules in one project. Follow these steps: 1. close the project 2. close Android...
Read more >Expo vs Vanilla React Native Development: What to Choose
You can't add native modules written in Objective-C, Swift, Java, Kotlin ... the packages linking works and how to set up an app...
Read more >expo-localization - npm
Add libEXLocalization.a to your project's Build Phases ➜ Link Binary With ... If your Android build cannot find the Native Modules, ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@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 init
project 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-application
is 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!