-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
Fix Binding JNI type #41657
Fix Binding JNI type #41657
Conversation
Can you link where in Reanimated we're depending on this method? We should prefer targeting the interface over the concrete implementation. |
Sure thing 🫡 |
I think we need to change Binding.h to split between Binding and BindingImpl. |
What do you prefer? Should I try to do it on my own, or just leave it and you guys will manage it internally? |
Base commit: 25196ba |
This hasn't been raised as a blocker internally so far, so would definitely appreciate a PR for this. Here's an example of a concrete hybrid class implementing an interface: react-native/packages/react-native/ReactAndroid/src/main/jni/react/jni/JCallback.h Line 26 in 86c5aba
|
@javache I applied your suggested changes. Could you take a look? 🙏 |
|
||
return getFieldValue(bindingField)->cthis(); | ||
return jni::static_ref_cast<Binding::javaobject>(getFieldValue(bindingField))->cthis(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is somewhat risky, if you do use a different Binding implementation, this cast will not be valid, but that's a pre-existing issue here.
@javache has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
This pull request was successfully merged by @piaskowyk in 31d8a93. When will my fix make it into a release? | Upcoming Releases |
Summary: New implementation: This PR adds cast from interface Binding to BindingImpl class. Previous implementation: The changes made in this PR make the `mBinding` field of `FabricUIManager` visible for JNI. Without these changes, calling the method `JFabricUIManager::getBinding()` would result in an error. <img width="400" alt="Screenshot 2023-11-27 at 13 55 44" src="https://github.com/facebook/react-native/assets/36106620/04418291-8ce8-4bae-b16c-29a5c9f2ee52"> In the `react-native-reanimated` library, we utilize `JFabricUIManager::getBinding()`, and we have noticed this issue since version 0.73. This isn't perfect solution, but I'm not certain which change in RN or FBJNI is the source of the problem. If there are any alternative solutions worth considering, I am open to discussing them. Usage of `getBinding()` in Reanimated: https://github.com/software-mansion/react-native-reanimated/blob/main/android/src/main/cpp/NativeProxy.cpp#L57 ## Changelog: [ANDROID] [FIXED] - Fix type for unrecognisable field mBinding Pull Request resolved: facebook/react-native#41657 Test Plan: Just call `JFabricUIManager::getBinding` method (https://github.com/facebook/react-native/blob/v0.73.0-rc.5/packages/react-native/ReactAndroid/src/main/jni/react/fabric/JFabricUIManager.cpp#L14) or run app with repro: https://github.com/piaskowyk/missing-mBinding-repro after the app lunch you will receive error from above screenshot. Co-author: tomekzaw Reviewed By: NickGerleman Differential Revision: D51661873 Pulled By: javache fbshipit-source-id: 1891c36bf25c503ebc9b0501211df03be6f74115
Summary: New implementation: This PR adds cast from interface Binding to BindingImpl class. Previous implementation: The changes made in this PR make the `mBinding` field of `FabricUIManager` visible for JNI. Without these changes, calling the method `JFabricUIManager::getBinding()` would result in an error. <img width="400" alt="Screenshot 2023-11-27 at 13 55 44" src="https://github.com/facebook/react-native/assets/36106620/04418291-8ce8-4bae-b16c-29a5c9f2ee52"> In the `react-native-reanimated` library, we utilize `JFabricUIManager::getBinding()`, and we have noticed this issue since version 0.73. This isn't perfect solution, but I'm not certain which change in RN or FBJNI is the source of the problem. If there are any alternative solutions worth considering, I am open to discussing them. Usage of `getBinding()` in Reanimated: https://github.com/software-mansion/react-native-reanimated/blob/main/android/src/main/cpp/NativeProxy.cpp#L57 ## Changelog: [ANDROID] [FIXED] - Fix type for unrecognisable field mBinding Pull Request resolved: #41657 Test Plan: Just call `JFabricUIManager::getBinding` method (https://github.com/facebook/react-native/blob/v0.73.0-rc.5/packages/react-native/ReactAndroid/src/main/jni/react/fabric/JFabricUIManager.cpp#L14) or run app with repro: https://github.com/piaskowyk/missing-mBinding-repro after the app lunch you will receive error from above screenshot. Co-author: tomekzaw Reviewed By: NickGerleman Differential Revision: D51661873 Pulled By: javache fbshipit-source-id: 1891c36bf25c503ebc9b0501211df03be6f74115
<!-- Thanks for submitting a pull request! We appreciate you spending the time to work on these changes. Please follow the template so that the reviewers can easily understand what the code changes affect. --> ## Summary Keep fabric class to prevent crashes in react-native 0.73+ with new architecture and proguard. Fixes #5514 Related #5472, facebook/react-native#41657 <!-- Explain the motivation for this PR. Include "Fixes #<number>" if applicable. --> ## Test plan - Clone `gh repo clone ahmetbicer/mBinding-proguard-repro` - add `-keep class com.facebook.react.fabric.** { *; }` in your app proguard-rules.pro or reanimated node_modules folder - Run `yarn react-native run-android --mode Release` - Build and Open without crash 🎉 <!-- Provide a minimal but complete code snippet that can be used to test out this change along with instructions how to run it and a description of the expected behavior. -->
Summary: New implementation: This PR adds cast from interface Binding to BindingImpl class. Previous implementation: The changes made in this PR make the `mBinding` field of `FabricUIManager` visible for JNI. Without these changes, calling the method `JFabricUIManager::getBinding()` would result in an error. <img width="400" alt="Screenshot 2023-11-27 at 13 55 44" src="https://github.com/facebook/react-native/assets/36106620/04418291-8ce8-4bae-b16c-29a5c9f2ee52"> In the `react-native-reanimated` library, we utilize `JFabricUIManager::getBinding()`, and we have noticed this issue since version 0.73. This isn't perfect solution, but I'm not certain which change in RN or FBJNI is the source of the problem. If there are any alternative solutions worth considering, I am open to discussing them. Usage of `getBinding()` in Reanimated: https://github.com/software-mansion/react-native-reanimated/blob/main/android/src/main/cpp/NativeProxy.cpp#L57 ## Changelog: [ANDROID] [FIXED] - Fix type for unrecognisable field mBinding Pull Request resolved: facebook#41657 Test Plan: Just call `JFabricUIManager::getBinding` method (https://github.com/facebook/react-native/blob/v0.73.0-rc.5/packages/react-native/ReactAndroid/src/main/jni/react/fabric/JFabricUIManager.cpp#L14) or run app with repro: https://github.com/piaskowyk/missing-mBinding-repro after the app lunch you will receive error from above screenshot. Co-author: tomekzaw Reviewed By: NickGerleman Differential Revision: D51661873 Pulled By: javache fbshipit-source-id: 1891c36bf25c503ebc9b0501211df03be6f74115
Summary:
New implementation:
This PR adds cast from interface Binding to BindingImpl class.
Previous implementation:
The changes made in this PR make the
mBinding
field ofFabricUIManager
visible for JNI.Without these changes, calling the method
JFabricUIManager::getBinding()
would result in an error.In the
react-native-reanimated
library, we utilizeJFabricUIManager::getBinding()
, and we have noticed this issue since version 0.73. This isn't perfect solution, but I'm not certain which change in RN or FBJNI is the source of the problem. If there are any alternative solutions worth considering, I am open to discussing them.Usage of
getBinding()
in Reanimated:https://github.com/software-mansion/react-native-reanimated/blob/main/android/src/main/cpp/NativeProxy.cpp#L57
Changelog:
[ANDROID] [FIXED] - Fix type for unrecognisable field mBinding
Test Plan:
Just call
JFabricUIManager::getBinding
method (https://github.com/facebook/react-native/blob/v0.73.0-rc.5/packages/react-native/ReactAndroid/src/main/jni/react/fabric/JFabricUIManager.cpp#L14)or run app with repro:
https://github.com/piaskowyk/missing-mBinding-repro
after the app lunch you will receive error from above screenshot.
Co-author: @tomekzaw