NativeModules crashing in Release Builds
See original GitHub issueThe 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:
- Created 6 years ago
- Comments:5 (3 by maintainers)
@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
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.