Link Android libc++ explicitly#9590
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes Android NDK 27.x linker failures by explicitly linking c++_shared in the native CMake targets for both react-native-worklets and react-native-reanimated, ensuring libc++ is linked even when ANDROID_STL is passed but not consumed by the NDK toolchain.
Changes:
- Link
c++_sharedexplicitly inreact-native-workletsAndroid CMake target. - Link
c++_sharedexplicitly inreact-native-reanimatedAndroid CMake target.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/react-native-worklets/android/CMakeLists.txt | Adds c++_shared to worklets target link libraries to force libc++ shared linkage on NDK 27. |
| packages/react-native-reanimated/android/CMakeLists.txt | Adds c++_shared to reanimated target link libraries to force libc++ shared linkage on NDK 27. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
The two failing metadata checks look permission-related rather than code-related on this fork PR:
|
|
Hi @sorinc03, thanks for the PR. The fix looks good to me but I don't understand one thing - why is the explicit linking statement required in our CMakeLists.txt but not in React Native's React Android? https://github.com/facebook/react-native/blob/main/packages/react-native/ReactAndroid/src/main/jni/CMakeLists.txt#L261-L271 |
Summary
Fixes #9444.
This explicitly links
c++_sharedinto both Android native targets so NDK 27 builds include-lc++_sharedeven when CMake leavesANDROID_STLas an unconsumed cache variable.Test plan
Ran the fabric example native debug build with the repo-configured NDK 27.1.12297006:
The build completed successfully for
react-native-workletsandreact-native-reanimatedacrossarm64-v8a,armeabi-v7a,x86, andx86_64. Generated Ninja files include-lc++_sharedin both targets whileCMakeCache.txtstill showsANDROID_STL:UNINITIALIZED=c++_shared, matching the issue scenario.Also ran: