question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:11
  • Comments:12 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
Lukkubcommented, 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.

1reaction
tapzcommented, 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

Read more comments on GitHub >

github_iconTop Results From Across the Web

JNI NewGlobalRef called with pending exception java.lang ...
JNI DETECTED ERROR IN APPLICATION: JNI NewGlobalRef called with pending exception java.lang.ClassNotFoundException: ; android:name · ".data.
Read more >
Jni detected error in application - Android
JNI DETECTED ERROR IN APPLICATION: JNI GetMethodID called with pending exception java.lang.NoClassDefFoundError: Failed resolution of: ...
Read more >
runtime/check_jni.cc - platform/art - android Git repositories
when a native method that matches the -Xjnitrace argument calls a JNI function ... Thread" instead of "java/lang/Thread" might work in some.
Read more >
react-native-reanimated - Bountysource
After upgrading to react-native version 0.65.0 with reanimated 2.2.0 I got the following error: Execution failed for task ':app:mergeDebugAssets'.
Read more >
JNI DETECTED ERROR IN APPLICATION: JNI FindClass c...
JNI DETECTED ERROR IN APPLICATION: JNI FindClass called with pending exception java.lang.ClassNotFoundException: Didn't find class "com.esri.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found