You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native 0.55.4 Release构建崩溃:react-native-android-sms-listener异常

Fix for react-native-android-sms-listener Crash in Release Build (RN 0.55.4)

I’ve run into similar headaches with older React Native versions and third-party native modules, so let’s break down how to resolve this Release-only crash.

The Root Cause

The error undefined is not a function (evaluating 'arguments.[0].indexOf('Requiring module \'NativeModules\' by name')') tells us there’s a problem with how the module is resolved in Release mode. This usually stems from:

  • ProGuard obfuscating critical code that React Native needs to locate NativeModules
  • The module’s JS wrapper not playing nice with RN 0.55.4’s Release bundling/compression rules
  • Incomplete native module linking that only surfaces in Release builds (even though Debug works)

Step-by-Step Solutions

1. Update ProGuard Rules to Block Obfuscation

Open android/app/proguard-rules.pro and add these lines to protect the SMS listener module and core React Native bridge code from being mangled:

# Keep react-native-android-sms-listener classes intact
-keep class com.centaurwarchief.smslistener.** { *; }

# Protect core React Native NativeModules dependencies
-keep class com.facebook.react.modules.core.** { *; }
-keep class com.facebook.react.bridge.** { *; }

ProGuard loves stripping or renaming "unused" code in Release builds—this ensures the classes needed for JS-native communication stay intact.

2. Double-Check Native Module Linking

Even if Debug works, confirm the module is properly registered in your Android project:

  1. Open android/app/src/main/java/[your-package-name]/MainApplication.java
  2. Verify you have the import and package registration:
    import com.centaurwarchief.smslistener.SmsListenerPackage;
    
    // ...
    
    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
          new SmsListenerPackage() // Make sure this line exists!
      );
    }
    

If it’s missing, add it and re-run react-native link react-native-android-sms-listener to ensure all links are updated.

3. Bypass the Module’s JS Wrapper (Direct NativeModules Import)

The module’s built-in JS wrapper might be causing issues in Release mode. Try importing the module directly from NativeModules instead:
Replace your existing import:

import SmsListener from 'react-native-android-sms-listener';

With:

import { NativeModules } from 'react-native';
const SmsListener = NativeModules.SmsListener;

This skips any potentially problematic wrapper code and directly accesses the native module the way React Native expects.

4. Clean and Rebuild the Release Package

Old build artifacts can cause weird Release-only bugs. Run these commands to start fresh:

# Navigate to android directory and clean gradle
cd android && ./gradlew clean

# Bundle JS for Release
cd .. && react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/

# Build and run the Release variant
react-native run-android --variant=release

Final Notes

RN 0.55.4 is an older version, so compatibility with newer modules can hit snags. If the above steps don’t work, you might want to check if the module has open issues for older RN versions, or consider forking it to tweak the native/JS code to match RN 0.55.4’s expectations.

内容的提问来源于stack exchange,提问作者Nicolas

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 09:42:52