Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JNI DETECTED ERROR IN APPLICATION: JNI GetObjectRefType called with pending exception java.lang.RuntimeException: java.lang.AssertionError: Illegal type provided #2722

Closed
1 of 3 tasks
tapz opened this issue Dec 9, 2021 · 12 comments · Fixed by #2853
Labels
Bug bug-bash-jan22 Issues visited during Bug Bash Jan 2022 Crash Missing repro This issue need minimum repro scenario 🏠 Reanimated 2

Comments

@tapz
Copy link

tapz commented Dec 9, 2021

Description

The worklets in Reanimated v2 seems to be really unstable in Android. Every change in the worklet code crashes the app and the app needs to be restarted like 5 times (crashes 5 times). And if you have an error in the worklet (e.g. calling any standard javascript function like parseInt, Math.round etc) it crashes in the native code with always the same error.

If I move the code from onEnd worklet to a normal function and call it with runOnJS it either does nothing or the app crashes. Is runOnJS even supposed to work?

 java_vm_ext.cc:578] JNI DETECTED ERROR IN APPLICATION: JNI GetObjectRefType called with pending exception java.lang.RuntimeException: java.lang.AssertionError: Illegal type provided
 java_vm_ext.cc:578]   at void com.swmansion.reanimated.AndroidErrorHandler.raise(java.lang.String) (AndroidErrorHandler.java:6)
 java_vm_ext.cc:578]   at void com.swmansion.reanimated.Scheduler.triggerUI() (Scheduler.java:-2)
 java_vm_ext.cc:578]   at void com.swmansion.reanimated.Scheduler$1.run() (Scheduler.java:24)

Expected behavior

Crashes would be captured and a stack trace printed to the console. Or a proper error in the native logs. And when restarting the app after fixing the code (or not changing it at all when no bug in the code) the app would work in immediately not after 5 to 10 restarts (some caching issue?).

Actual behavior & steps to reproduce

Unhandled crashes and no proper recovery.

Snack or minimal code example

I'm using the pan gesture handler worklets with Samsung Galaxy A51 5G (SM-A516B).

Package versions

  • React Native: 0.66.3
  • React Native Reanimated: 2.3.0
  • React Native Gesture Handler: 2.1.0
  • NodeJS: 14.18.1
  • Java & Gradle: OpenJDK 64-Bit Server VM (build 14.0.2+12-46, mixed mode, sharing) & 7.3

Affected platforms

  • Android
  • iOS
  • Web
@github-actions
Copy link

github-actions bot commented Dec 9, 2021

Issue validator

The issue is valid!

@piaskowyk
Copy link
Member

Hey, could you provide a repo to reproduce your issue? Without repro, I am not able to help 😕

@piaskowyk piaskowyk added Missing repro This issue need minimum repro scenario Crash labels Dec 17, 2021
@tapz
Copy link
Author

tapz commented Dec 19, 2021

@piaskowyk Are you saying it's completely stable when you test?

@Lukkub
Copy link

Lukkub commented Dec 23, 2021

@piaskowyk @tapz
I found currently the same bug - on debug everything works fine, but on release variant random crashes occur with the same error logs as mentioned above.
Issue occurs only on Android.

@tapz
Copy link
Author

tapz commented Dec 23, 2021

@Lukkub In my case only the debug build crashes after I modify some file after app start. I guess that has something to do with Hermes and how RN updates the changed files. Release builds have never crashes with this error.

I have never got the 2.3.x to work in iOS. I had to create a separate implementation using the old gesture handler api and RN animations. Can't event import reanimated to an iOS app without it crashing with Undefined is not an object (evaluating 'InnernativeModule.installCoreFunctions'). Reanimated does not even compile in Xcode without changes to some include paths in header and source files.

@andreialecu
Copy link
Contributor

andreialecu commented Dec 29, 2021

Hey, could you provide a repo to reproduce your issue? Without repro, I am not able to help 😕

Hey @piaskowyk:

I finally tried updating to 2.3.1 as a prerequisite of updating to RN 0.67 after previously being stuck on 2.2.3, which was the last good version not to have this error. Not sure if you remember but I've been on a big rabbit hole trying to troubleshoot and create a repro for this in various threads.

Managed to create one here: #2256 (comment)

Anyways, the crash seems to be back after updating to RN 0.67-rc.6 + Reanimated 2.3.1 and forcing Hermes to version 0.10.0 via yarn resolutions. It's likely these steps are not necessary.

java_vm_ext.cc:579] JNI DETECTED ERROR IN APPLICATION: JNI GetObjectRefType called with pending exception java.lang.RuntimeException: java.lang.AssertionError: Illegal type provided
java_vm_ext.cc:579]   at void com.swmansion.reanimated.AndroidErrorHandler.raise(java.lang.String) (AndroidErrorHandler.java:6)
java_vm_ext.cc:579]   at void com.swmansion.reanimated.Scheduler.triggerUI() (Scheduler.java:-2)
java_vm_ext.cc:579]   at void com.swmansion.reanimated.Scheduler$1.run() (Scheduler.java:24)
java_vm_ext.cc:579]   at void com.swmansion.reanimated.Scheduler$2.runGuarded() (Scheduler.java:43)
java_vm_ext.cc:579]   at void com.facebook.react.bridge.GuardedRunnable.run() (GuardedRunnable.java:31)
java_vm_ext.cc:579]   at void android.os.Handler.handleCallback(android.os.Message) (Handler.java:938)
java_vm_ext.cc:579]   at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:99)
java_vm_ext.cc:579]   at boolean android.os.Looper.loopOnce(android.os.Looper, long, int) (Looper.java:201)
java_vm_ext.cc:579]   at void android.os.Looper.loop() (Looper.java:288)
java_vm_ext.cc:579]   at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:7798)
java_vm_ext.cc:579]   at java.lang.Object java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object[]) (Method.java:-2)
java_vm_ext.cc:579]   at void com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run() (RuntimeInit.java:548)
java_vm_ext.cc:579]   at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:1003)
java_vm_ext.cc:579] 
java_vm_ext.cc:579]     in call to GetObjectRefType
java_vm_ext.cc:579]     from void com.swmansion.reanimated.Scheduler.triggerUI()

Were you not able to reproduce the problem with the above repro?

@priyanka17-maker
Copy link

@Lukkub In my case only the debug build crashes after I modify some file after app start. I guess that has something to do with Hermes and how RN updates the changed files. Release builds have never crashes with this error.

I have never got the 2.3.x to work in iOS. I had to create a separate implementation using the old gesture handler api and RN animations. Can't event import reanimated to an iOS app without it crashing with Undefined is not an object (evaluating 'InnernativeModule.installCoreFunctions'). Reanimated does not even compile in Xcode without changes to some include paths in header and source files.

@tapz what changes u did?? I am facing a same issue.. release build never crashed with this error but while testing the app on physical device its get crashed.and fortunately its working fine on ios..dont know whats wrong with android.can u please tell me what changes u did in files?? Your help will be really appreciated.Thanks

@Lukkub
Copy link

Lukkub commented Jan 3, 2022

Hi @priyanka17-maker @andreialecu @tapz

I would like to share with you my solution for my case.

PROBLEM
Works fine on debug builds for both Android and iOS, but crash on Android release - iOS on release build still works fine.

REASON
I figure out that android crash because of useAnimatedStyle objects that are applied to the animated.view component on first mount.

HACK FIX for a problem
For Android only - I created special state with effect to delay applying animatedstyle objects to the components.
Simple timeout with 500 ms (value is just random - just not apply style object on first mount) - and no crash appear on android

Effect looks like that:

  useEffect(() => {
    if (Platform.OS === 'ios') {
      return;
    }

    const timeoutId = setTimeout(() => {
      setAllowAnimatedStyle(true);
    }, ALLOW_ANIMATED_STYLE_TIMEOUT);

    return () => clearTimeout(timeoutId);
  }, []);

Then applying style objects looks like that:

  const animatedViewStyle = useMemo(
    () => [
      styles.animatedContainer,
      !allowAnimatedStyle ? {} : animatedFocusedStyle,
    ],
    [allowAnimatedStyle, animatedFocusedStyle],
  );

I hope this will help you somehow - and maybe it will help to detect the real reason for this crash on Android.

@tapz
Copy link
Author

tapz commented Jan 3, 2022

@Lukkub I haven't changed anything. It has always crashed only in debug builds after the first reload. And in iOS, it has never worker in the debug or the release build (but the reason and error is different than in Android).

Here is an example that works perfectly in Android, but not at all in iOS:

https://github.com/tapz/reanimatederror-example

@andreialecu
Copy link
Contributor

For Android only - I created special state with effect to delay applying animatedstyle objects to the components.
Simple timeout with 500 ms (value is just random - just not apply style object on first mount) - and no crash appear on android

These were exactly my findings here: #2256 (comment)

I also found out that if you add a small delay the crash doesn't occur. I'm not sure why @piaskowyk has been ignoring my repro 😆

@xD3CODER
Copy link

xD3CODER commented Jan 3, 2022

@Lukkub I confirm this workaround works in my case

@Omelyan
Copy link

Omelyan commented Jan 10, 2022

@Lukkub yeap, can confirm this too. Spent several hours till got to affected useAnimatedStyle and this workaround... 2.3.x is so buggy actually compared to 2.2.x

@kkafar kkafar added the bug-bash-jan22 Issues visited during Bug Bash Jan 2022 label Jan 28, 2022
piaskowyk pushed a commit that referenced this issue Feb 2, 2022
## Description

Sometimes RN passes ReadableMap/Array instead of WritableMap/Array when updateProps is called. Currently adding a ReadableMap/Array to a WritableMap/Array is not supported (I opened a PR to allow it since there's no reason it can't be allowed facebook/react-native#32910). In the meantime we have to check if it's not Writable and copy before adding it.

Fixes #2722

## Changes


## Screenshots / GIFs

N/A

## Test code and steps to reproduce

I'm not sure exactly what the minimum repro is, I could 100% repro the crash in an app, but wasn't able to isolate. The app makes heavy usage of a bottom sheet lib that uses reanimated. I was able to repro a few times in the example app with the repro in the linked issue, but not consistently.

In the app where I could repro consistently I verified that it no longer crashes after this change.

## Checklist

- [ ] Included code example that can be used to test this change
- [ ] Updated TS types
- [ ] Added TS types tests
- [ ] Added unit / integration tests
- [ ] Updated documentation
- [ ] Ensured that CI passes
aeddi pushed a commit to aeddi/react-native-reanimated that referenced this issue Mar 22, 2022
## Description

Sometimes RN passes ReadableMap/Array instead of WritableMap/Array when updateProps is called. Currently adding a ReadableMap/Array to a WritableMap/Array is not supported (I opened a PR to allow it since there's no reason it can't be allowed facebook/react-native#32910). In the meantime we have to check if it's not Writable and copy before adding it.

Fixes software-mansion#2722

## Changes


## Screenshots / GIFs

N/A

## Test code and steps to reproduce

I'm not sure exactly what the minimum repro is, I could 100% repro the crash in an app, but wasn't able to isolate. The app makes heavy usage of a bottom sheet lib that uses reanimated. I was able to repro a few times in the example app with the repro in the linked issue, but not consistently.

In the app where I could repro consistently I verified that it no longer crashes after this change.

## Checklist

- [ ] Included code example that can be used to test this change
- [ ] Updated TS types
- [ ] Added TS types tests
- [ ] Added unit / integration tests
- [ ] Updated documentation
- [ ] Ensured that CI passes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug bug-bash-jan22 Issues visited during Bug Bash Jan 2022 Crash Missing repro This issue need minimum repro scenario 🏠 Reanimated 2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants