microsoft / react-native-code-push

React Native module for CodePush
http://appcenter.ms
Other
8.98k stars 1.47k forks source link

Android crash after bundle install #2258

Closed leolusoli closed 2 years ago

leolusoli commented 2 years ago

Hi all, I'm trying to integrate the library inside a react-native 0.65.1 project (classical architecture from the template). The set-up goes well and iOS work perfectly. The problem I'm facing: after code-push download the bundle and plan the install, the Android app crash after installing the bundle with the ugly error: TypeError: Cannot read property 'split' of undefined - Hermes engine.

Steps to Reproduce

  1. Publish a React bundle to app center
  2. assembleRelease a version and install it inside the emulator for test the behaviour
  3. Start the application and wait the bundle will be downloaded from AppCenter.
  4. Background / Foreground for trigger the install.
  5. The app crash.

Expected Behavior

If iOS works correctly, I'm expecting that even Android works fine.

Actual Behavior

The Android crash after install the new bundle. If I retry to re-open the app, the application rollback the previous correct bundle.

Reproducible Demo

Another point of interest is that I also facing the: [CodePush] Unable to get the hash of the binary's bundled resources - "codepush.gradle" may have not been added to the build definition. problem. The app don't crash for this cause, but the message appears in the logcat. I already tried every suggestions found inside the issues for the repo regarding this warning but nothing works.

I follow the classic set-up for react-native >= 0.60.

Don't esitate to contact me if you want more informations.

Environment

FadiAboMsalam commented 2 years ago

@leolusoli am facing the same issue also but I am on RN0.67.4 it works fine on ios but the app crash after bundle install with same crash

Fatal Exception: com.facebook.react.common.c TypeError: Cannot read property 'split' of undefined, js engine: hermes, stack: anonymous@738:218 h@2:1585 d@2:1028 o@2:496 anonymous@731:127 h@2:1585 d@2:1028 o@2:496 anonymous@730:117 h@2:1585 d@2:1028 o@2:496 anonymous@677:150 h@2:1585 d@2:1028 o@2:496 anonymous@6:67 h@2:1585 d@2:958 o@2:496 global@5163:3

if you find any fixes please let me know

leolusoli commented 2 years ago

@leolusoli am facing the same issue also but I am on RN0.67.4 it works fine on ios but the app crash after bundle install with same crash

Fatal Exception: com.facebook.react.common.c TypeError: Cannot read property 'split' of undefined, js engine: hermes, stack: anonymous@738:218 h@2:1585 d@2:1028 o@2:496 anonymous@731:127 h@2:1585 d@2:1028 o@2:496 anonymous@730:117 h@2:1585 d@2:1028 o@2:496 anonymous@677:150 h@2:1585 d@2:1028 o@2:496 anonymous@6:67 h@2:1585 d@2:958 o@2:496 global@5163:3

if you find any fixes please let me know

What a "beautiful" news. I was wondering if I have something wrong in my project. This confirm that is not only my issue. Thanks a lot.

Please consider to get a look to it. Is not possible to use your library with this strange behaviour.

leolusoli commented 2 years ago

@FadiAboMsalam Incredible! I found it.

I turn off Hermes in Android and the crash become like this: undefined is not an object (evaluating 'o(a[1]).NativeModules.SourceCode.scriptURL.split("://")[1].split')

So, I searched this stuff on web and I found this issue inside the repo. So I start to investigating in Reactotron (set up made by another team). I found those lines inside a configuration js code:

const { scriptURL } = NativeModules.SourceCode; const [scriptHostname] = scriptURL.split('://')[1].split(':')

So I change this code to the following

const [scriptHostname] = scriptURL?.split('://')[1]?.split(':') ?? 'localhost';

and CodePush start working even in Android.

PS: My 2 cent please.... was a tough one πŸ˜‚

FadiAboMsalam commented 2 years ago

@leolusoli thank man you are a Life saver it was indeed my issue as well ! appreciate that bro your 2 cents are ready man πŸ˜‚

Thanh-Long-Vu commented 8 months ago

@FadiAboMsalam Incredible! I found it.

I turn off Hermes in Android and the crash become like this: undefined is not an object (evaluating 'o(a[1]).NativeModules.SourceCode.scriptURL.split("://")[1].split')

So, I searched this stuff on web and I found this issue inside the repo. So I start to investigating in Reactotron (set up made by another team). I found those lines inside a configuration js code:

const { scriptURL } = NativeModules.SourceCode; const [scriptHostname] = scriptURL.split('://')[1].split(':')

So I change this code to the following

const [scriptHostname] = scriptURL?.split('://')[1]?.split(':') ?? 'localhost';

and CodePush start working even in Android.

PS: My 2 cent please.... was a tough one πŸ˜‚

Where can you know line (const [scriptHostname] = scriptURL?.split('://')[1]?.split(':') ?? 'localhost') fix in project?

kashifdroidley3435 commented 6 months ago

Hey @leolusoli could you please let us know where is this line is in the project?

nvdnvd00 commented 4 months ago

It still happen in 2024 react-native: 0.72.4 and code-push 8.2.2

I tried to remove everything related to reactotron but id didn't resolve the issue

Update: It works when I run it in debug mode

matheusmhq commented 1 month ago

@FadiAboMsalam Incredible! I found it.

I turn off Hermes in Android and the crash become like this: undefined is not an object (evaluating 'o(a[1]).NativeModules.SourceCode.scriptURL.split("://")[1].split')

So, I searched this stuff on web and I found this issue inside the repo. So I start to investigating in Reactotron (set up made by another team). I found those lines inside a configuration js code:

const { scriptURL } = NativeModules.SourceCode; const [scriptHostname] = scriptURL.split('://')[1].split(':')

So I change this code to the following

const [scriptHostname] = scriptURL?.split('://')[1]?.split(':') ?? 'localhost';

and CodePush start working even in Android.

PS: My 2 cent please.... was a tough one πŸ˜‚

Thank you very much, your comment led me to the solution. In my case, I added a conditional to load the ReactotronConfig only in the development environment.

if (__DEV__) {
    import('./config/ReactotronConfig');
}