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

React Native Android应用Facebook登录/取消时崩溃求助

Answer

Root Cause Analysis

Looking closely at your ADB crash logs, the issue isn't related to your Facebook Login code or react-native-fbsdk directly. The crash is triggered by a null pointer exception in the UpiPaymentModule when it tries to handle the activity result from Facebook Login:

Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'void com.facebook.react.bridge.Callback.invoke(java.lang.Object[])' on a null object reference
at com.upi.payment.UpiPaymentModule.onActivityResult(UpiPaymentModule.java:102)

When any activity (like Facebook Login) finishes and returns a result, all React Native native modules that override onActivityResult receive this result. The UpiPaymentModule is attempting to call a callback that's already null, leading to the app crash.

Solution

Step 1: Fix the UpiPaymentModule Native Code

  1. Navigate to your Android project's native code directory and find UpiPaymentModule.java (typically located at android/app/src/main/java/com/upi/payment/ or a similar path depending on how the module was installed).
  2. Update the onActivityResult method to add a null check for the callback before invoking it:
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        // Add this null check to prevent the crash
        if (mCallback == null) {
            super.onActivityResult(requestCode, resultCode, data);
            return;
        }
    
        // Keep your existing logic here
        // ...
    }
    
    Note: If the module uses a different variable name for the callback (e.g., callback instead of mCallback), adjust the check to match.

Step 2: Clean and Rebuild Your Project

After making the code change, clean and rebuild your Android project to ensure the fix takes effect:

cd android
./gradlew clean
react-native run-android

Alternative: Update the UPI Payment Package

If you're using a third-party npm package for UPI payments, check if there's an updated version of the package that addresses this null pointer issue. If an update is available, install it with:

npm install [upi-payment-package-name]@latest --save

Additional Notes

Your Facebook Login code looks correct—since the crash is coming from a different module, fixing the UpiPaymentModule should resolve the issue without needing to modify your React Native login logic.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.08 18:52:52