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.

NativeModules crashing in Release Builds

See original GitHub issue

The app runs perfectly fine in debug mode on Android. However, when I attempt to build a release version the app crashes whenever it attempts to call into the native module.

Environment

nvironment: OS: macOS High Sierra 10.13.3 Node: 9.5.0 Yarn: 1.3.2 npm: 5.6.0 Watchman: 4.9.0 Xcode: Xcode 9.2 Build version 9C40b Android Studio: 3.0 AI-171.4443003

Packages: (wanted => installed) react: 16.2.0 => 16.2.0 react-native: 0.54.0 => 0.54.0

Expected Behavior

Native Module should be available inside of the JavaScript and not crash.

Actual Behavior

App crashes. com.facebook.react.common.JavascriptException: undefined is not an object (evaluating 'c.NativeModules.ActivityModule.finishActivity'), stack:

Steps to Reproduce

ActivityModule.kt

internal class ActivityModule(reactContext: ReactApplicationContext): ReactContextBaseJavaModule(reactContext) {
  override fun getName(): String {
    return "ActivityModule"
  }

  @ReactMethod
  fun finishActivity() {
    reactApplicationContext?.currentActivity?.finish()
  }
}

MyReactPackage.kt

internal class MyReactPackage: ReactPackage {
  override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
    return listOf(
      ActivityModule(reactContext),
      DimensionsModule(reactContext)
    )
  }

  override fun createViewManagers(reactContext: ReactApplicationContext?): MutableList<com.facebook.react.uimanager.ViewManager<View, ReactShadowNode<*>>> {
    return Collections.emptyList()
  }
}

MainApplication.java

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

fake-navigation.js

const finish = () => {
  NativeModules.ActivityModule.finishActivity();
};

Calling the finish() function above crashes the app

E/ReactNativeJS: undefined is not an object (evaluating 'c.NativeModules.ActivityModule.finishActivity')
E/AndroidRuntime: FATAL EXCEPTION: mqt_native_modules
        Process: com.myapp.app, PID: 15496
        com.facebook.react.common.JavascriptException: undefined is not an object (evaluating 'c.NativeModules.ActivityModule.finishActivity')

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
mdvaccacommented, Mar 6, 2018

@scottschmitz Do you have proguard enabled? If so, can you try to disabling proguard and test if this still happens in Release mode? https://facebook.github.io/react-native/docs/signed-apk-android.html

1reaction
scottschmitzcommented, Mar 6, 2018

Thanks! It was in fact a proguard issue. I didn’t realize that when I added React Native to my project that the proguard rules were not added into the folder with my other rules.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React native app is crashing only on release build
But it not working on release build. When SMS recived I have crash without error message. In android logs I found this:
Read more >
Fixing React-Native android release build - wesionaryTEAM
Android release build crashes on launch but works fine in development mode. After months of research and development, your app is finally ready...
Read more >
Release Notes for v20.0.0 - Electron Releases
#35137; Fixed spontaneous crashing in native modules that depended on nan . ... 19); Fixed symbol generation on 32-bit Windows release builds.
Read more >
Troubleshooting Native Modules · React Native for Windows + ...
The symptoms are that building the app will work fine but the C++ app will crash at runtime when trying to load the...
Read more >
Using Hermes - React Native
To see the benefits of Hermes, try making a release build/deployment of your app to compare. For example: $ npx react-native run-android ...
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