Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NativeModules crashing in Release Builds #18204

Closed
scottschmitz opened this issue Mar 5, 2018 · 5 comments
Closed

NativeModules crashing in Release Builds #18204

scottschmitz opened this issue Mar 5, 2018 · 5 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@scottschmitz
Copy link

scottschmitz commented Mar 5, 2018

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')
@grabbou
Copy link
Contributor

grabbou commented Mar 5, 2018

Interesting. Can you try seeing if this still happens on 0.54.x? I'll post this issue in the meantime onto the team.

CC: @hramos

@scottschmitz
Copy link
Author

I upgraded to 0.54.0 (and updated my environment above) and the issue is still occurring.

@hramos
Copy link
Contributor

hramos commented Mar 5, 2018

Thanks for the ping - I am unfamiliar with this area of the code. Did this regress recently?

@mdvacca
Copy link
Contributor

mdvacca commented 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

@scottschmitz
Copy link
Author

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.

@facebook facebook locked as resolved and limited conversation to collaborators Mar 6, 2019
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Mar 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

5 participants