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

Fix Binding JNI type #41657

Closed

Conversation

piaskowyk
Copy link
Contributor

@piaskowyk piaskowyk commented Nov 27, 2023

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.

Screenshot 2023-11-27 at 13 55 44

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

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

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. p: Software Mansion Partner: Software Mansion Partner Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. labels Nov 27, 2023
@javache
Copy link
Member

javache commented Nov 27, 2023

Can you link where in Reanimated we're depending on this method? We should prefer targeting the interface over the concrete implementation.

@piaskowyk
Copy link
Contributor Author

@javache
Copy link
Member

javache commented Nov 27, 2023

I think we need to change Binding.h to split between Binding and BindingImpl.

@piaskowyk
Copy link
Contributor Author

What do you prefer? Should I try to do it on my own, or just leave it and you guys will manage it internally?

@analysis-bot
Copy link

analysis-bot commented Nov 27, 2023

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 17,680,990 +118
android hermes armeabi-v7a n/a --
android hermes x86 n/a --
android hermes x86_64 n/a --
android jsc arm64-v8a 21,064,014 +108
android jsc armeabi-v7a n/a --
android jsc x86 n/a --
android jsc x86_64 n/a --

Base commit: 25196ba
Branch: main

@javache
Copy link
Member

javache commented Nov 27, 2023

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:

class JCxxCallbackImpl : public jni::HybridClass<JCxxCallbackImpl, JCallback> {

@piaskowyk
Copy link
Contributor Author

piaskowyk commented Nov 28, 2023

@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();
Copy link
Member

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.

@facebook-github-bot
Copy link
Contributor

@javache has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

Copy link

This pull request was successfully merged by @piaskowyk in 31d8a93.

When will my fix make it into a release? | Upcoming Releases

@github-actions github-actions bot added the Merged This PR has been merged. label Nov 30, 2023
douglowder pushed a commit to react-native-tvos/react-native-tvos that referenced this pull request Nov 30, 2023
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
huntie pushed a commit that referenced this pull request Dec 7, 2023
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
github-merge-queue bot pushed a commit to software-mansion/react-native-reanimated that referenced this pull request Jan 9, 2024
<!-- 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. -->
Othinn pushed a commit to Othinn/react-native that referenced this pull request Jan 9, 2024
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. p: Software Mansion Partner: Software Mansion Partner Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants