question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ExpoKit (Android) Cannot Link Native Modules

See original GitHub issue

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. image

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:20 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
ChildishDanbinocommented, Dec 4, 2017

@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


import android.support.multidex.MultiDexApplication;


import com.facebook.react.ReactPackage;
import com.facebook.react.ReactApplication;
import com.facebook.react.ReactNativeHost;

import com.wix.reactnativenotifications.RNNotificationsPackage;

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
  public ReactNativeHost getReactNativeHost() {
    return mReactNativeHost;
  }

  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()
            new RNNotificationsPackage(MainApplication.this)
    );
  }

}
2reactions
ChildishDanbinocommented, Nov 11, 2017

@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:

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

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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found