Android Pure C++ Turbo Module Static & Shared Library #287
Unanswered
Zach-Dean-Attractions-io
asked this question in
Q&A
Replies: 1 comment 1 reply
-
That's not correct. You can use either a SHARED or a STATIC library to achieve what you're trying to do .
That would help. If you could use this template: https://github.com/react-native-community/reproducer-react-native we could look into it |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In this repository I have a library which implements a pure C++ Turbo Module.
The Android CMakeLists.txt file looks like so
However, I want the ability to call from Java back into C++ and then call a method say in
PureCppImpl.cpp
. To call into C++ from Java I need to use aSHARED
library instead of aSTATIC
library. I planned to create a newSHARED
library alongside thisSTATIC
library, which would have a C++ file that imports thePureCppImpl.h
file. However, thisSHARED
library isn't simple to set up due to a lot of missing include directories.To illustrate this, if I change the
add_library
statement to the followingThen I get an error here that
<RNPureCppTurboModuleLibrarySpecJSI.h>
can not be found. If I then update thetarget_include_directories
to include that filetarget_include_directories( pure-cpp-turbo-module-library PUBLIC ../cpp + generated/jni/react/renderer/components/RNPureCppTurboModuleLibrarySpec )
Then I get an error in the file
RNPureCppTurboModuleLibrarySpecJSI.h
that the file'ReactCommon/TurboModule.h'
can not be found. So I then add this into thetarget_include_directories
target_include_directories( pure-cpp-turbo-module-library PUBLIC ../cpp generated/jni/react/renderer/components/RNPureCppTurboModuleLibrarySpec + ${CMAKE_CURRENT_SOURCE_DIR}/../node_modules/react-native/ReactCommon/react/nativemodule/core )
I then get another error for
#include <jsi/jsi.h>
.I've been carrying on in this way with the
SHARED
library but I run into a lot of issues. In my case because theSHARED
library I have needs to call into a file in theSTATIC
library, I think (but not fully sure) that when the shared library is compiled that it doesn't have all the include statements that for some reason (I'm not sure why) I get for free with the static library. Although once I have the shared library that depends on the static library it seems to break the static library too. At some point it even fails with the error that the libraryreact_codegen_RNPureCppTurboModuleLibrarySpec
can't be found and so I had to remove the generated CMakeLists.txt file that creates that library and define it myself. However, even after this I ran into issues with the import<folly/dynamic.h>
which I couldn't solve.Is there an easier way to do this?
I can provide a full example of what I am trying to achieve by calling from C++ into Java and then back into C++ if that will help.
Beta Was this translation helpful? Give feedback.
All reactions