react-native-push-notification / ios

React Native Push Notification API for iOS.
MIT License
731 stars 280 forks source link

Crash Caused in Android, with potential solution provided #431

Closed terryatgithub closed 1 month ago

terryatgithub commented 5 months ago

Hi! ๐Ÿ‘‹ Firstly, thanks for your work on this project! ๐Ÿ™‚

issue descriptions since this statement https://github.com/react-native-push-notification/ios/blob/904a99fdfa54f25b41c0a5141b4342b8c67b9616/android/app/build.gradle#L79

would cause a crash issue in Android like this: couldn't find DSO to load: libhermes.so

potential solution

would you consider fixing it, as the react-native official recommendation here: https://github.com/facebook/react-native/blob/7ea7d946c643f076c29bcf11b927f7569e3c516f/react.gradle#L18

image

my trial solutions(still under testing)

Today I used patch-package to patch @react-native-community/push-notification-ios@1.8.0 for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/@react-native-community/push-notification-ios/android/app/build.gradle b/node_modules/@react-native-community/push-notification-ios/android/app/build.gradle
index b857787..89613b1 100644
--- a/node_modules/@react-native-community/push-notification-ios/android/app/build.gradle
+++ b/node_modules/@react-native-community/push-notification-ios/android/app/build.gradle
@@ -1,4 +1,5 @@
 apply plugin: "com.android.application"
+apply plugin: "com.facebook.react"

 import com.android.build.OutputFile

@@ -76,7 +77,7 @@ project.ext.react = [
     entryFile: "index.js"
 ]

-apply from: "../../node_modules/react-native/react.gradle"
+// apply from: "../../node_modules/react-native/react.gradle"

 /**
  * Set this to true to create two separate APKs instead of one:

This issue body was partially generated by patch-package.

if any misunderstanding please let me know, thank you so much.

abdymm commented 2 months ago

oh yea, we just got it on our prod, errors after upgrading to RN 72, so its possibly coming from this lib?

terryatgithub commented 1 month ago

we referred this comment https://github.com/facebook/react-native/issues/36048#issuecomment-1456157287

our solution code as below for reference

    private final ReactNativeHost mReactNativeHost =
                new DefaultReactNativeHost(this) {
                @Override
                public boolean getUseDeveloperSupport() {
                    return BuildConfig.DEBUG;
                }

                @Override
                protected List<ReactPackage> getPackages() {
                    return getPackageFromMainFeature();
                }

                @Override
                protected String getJSMainModuleName() {
                    return "index";
                }

+                @Override
+                protected @Nullable JavaScriptExecutorFactory getJavaScriptExecutorFactory() {
+                   // because ReactNativeHost is overriden here, specify the HermesExecutorFactory():
+                  // refer: https://github.com/facebook/react-native/issues/36048#issuecomment-1456157287
+                 return new HermesExecutorFactory();
+            }

                @Override
                protected boolean isNewArchEnabled() {
                    return BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;
                }
                @Override
                protected Boolean isHermesEnabled() {
                    return BuildConfig.IS_HERMES_ENABLED;
                }
            };

    @Override
    public ReactNativeHost getReactNativeHost() {
        return mReactNativeHost;
    }