react-native-svg: [Android] [Reanimated] crash with react-native-svg 13.0.0
Bug
After update from react-native-svg 12.1.0 to 13.0.0 I have a crash on android with the following stack trace
java_vm_ext.cc:577] JNI DETECTED ERROR IN APPLICATION: JNI GetObjectRefType called with pending exception java.lang.RuntimeException: Exception in HostFunction: java.lang.ClassCastException: java.lang.Double cannot be cast to java.lang.String
java_vm_ext.cc:577]
java_vm_ext.cc:577] [native code]
java_vm_ext.cc:577] /Users/mlecoq/issues/reactNativeSvg13/node_modules/react-native-reanimated/src/reanimated2/UpdateProps.ts (46:26):1:267
java_vm_ext.cc:577] forEach@[native code]
java_vm_ext.cc:577] _f@/Users/mlecoq/issues/reactNativeSvg13/node_modules/react-native-reanimated/src/reanimated2/UpdateProps.ts (46:26):1:229
java_vm_ext.cc:577] [native code]
java_vm_ext.cc:577] styleUpdater@/Users/mlecoq/issues/reactNativeSvg13/node_modules/react-native-reanimated/src/reanimated2/hook/useAnimatedStyle.ts (185:0):1:1810
Unexpected behavior
Crash occurs since 13.0.0
Environment info
Run react-native info in your terminal and copy the results here. Also, include the precise version number of this library that you are using in the project
React native info output:
System:
OS: macOS 12.5.1
CPU: (10) arm64 Apple M1 Pro
Memory: 105.06 MB / 16.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 16.13.1 - /var/folders/md/1qkynwbs1216d57grkbc682h0000gn/T/fnm_multishells/19554_1661241167202/bin/node
Yarn: 1.22.15 - /var/folders/md/1qkynwbs1216d57grkbc682h0000gn/T/fnm_multishells/19554_1661241167202/bin/yarn
npm: 8.1.2 - /var/folders/md/1qkynwbs1216d57grkbc682h0000gn/T/fnm_multishells/19554_1661241167202/bin/npm
Watchman: 2022.03.21.00 - /opt/homebrew/bin/watchman
Managers:
CocoaPods: 1.11.3 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 21.4, iOS 15.5, macOS 12.3, tvOS 15.4, watchOS 8.5
Android SDK: Not Found
IDEs:
Android Studio: 2020.3 AI-203.7717.56.2031.7935034
Xcode: 13.4.1/13F100 - /usr/bin/xcodebuild
Languages:
Java: 11.0.13 - /usr/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: 18.0.0 => 18.0.0
react-native: 0.69.4 => 0.69.4
react-native-macos: Not Found
npmGlobalPackages:
*react-native*: Not Found
Library version: 13.0.0
Steps To Reproduce
Issues without reproduction steps or code are likely to stall.
- git clone https://github.com/mlecoq/reactNativeSvg13
- cd reactNativeSvg13
- yarn
- yarn android
The project crashes at startup (no crash with 12.1.0)
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 5
- Comments: 33 (11 by maintainers)
Commits related to this issue
- add example for #1845 — committed to buschco/react-native-svg by buschco 2 years ago
As pointed in the https://github.com/react-native-svg/react-native-svg/issues/1845#issuecomment-1247009705, the best way to handle
fillandstrokeprops in by usingcreateAnimatedPropAdapterwhich was made for this particular case, where props on the native side have different structure than in JS. Also, I changed thevalueprop topayloadso it does not confusereanimatedbabel plugin. YouranimatedPropsshould look e.g. like this:Turns out my
java.lang.Double cannot be cast to com.facebook.react.bridge.ReadableMapwas just a misleading error message. Double check the props you’re passing to<SVG– I was accidentally passing an empty string""for thefillprop on an svg text element. For some reason that got converted to ajava.lang.Doubleresulting in the confusing error message.@MarlonAEC I spent went way too long on this example lol, hope it helps! https://snack.expo.dev/@oiver55/svg-reanimated-example-path-fill?platform=android
Unfortunately super weird behavior on Android with Reanimated, useAnimatedProps barely seems to work anymore 😕
This code worked well in 12.4.0, but does not work now (no crash, but it does nothing):
Guys, If i want to use
fillproperty viauseAnimatedProps. Example:In version 12.3.0 it is working, on 13+ i have similar error. Or i do something incorrect?
Hey @oiver555 I really love the effort you put into this example actually it helped me understand a bunch of things from
react-native-reanimated. Now the thing is that I was looking for a way to do it using thisAnimatedfromreact-nativeNOT the one fromreact-native-reanimated. Thanks for your example again it showed me a bunch of cool stuff I haven’t tried with reanimited library! Super helpful!Hey @WoLewicki
How will we do it in this case?
@WoLewicki thank you it works like a charm 😍
Ok I will close this issue then. Feel free to comment here if something is wrong and we can always reopen it then.
Yes I just saw your example with the adapter, it works fine now, thanks a lot !
Unfortunately I don’t think it is. Since
react-native-reanimatedupdates the props directly and does not go through render method, the typings may differ there leading to a crash 😞Hi there, I add this here. I have no animation with react-content-loader since react-native-svg 13.0.0 only on Android. Everything works fine on iOS. And I have a fatal crash with this error:
This library doesn’t use reanimated but seems to use animation from react-native.
Here an content-loader example:
@WoLewicki thanks for your explanations, yes I started first to stringify params but since my code was failing on stroke (which expects ReadableMap), I did not dig any further.