-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
Using Core C++ library to share code between iOS and Android #634
Comments
Okay I see. I'll try to use Objective-C++ and JNI then, since I'm writing the compatibility layer for React Native in JSI. Thanks @lingol ! |
If you really really want to use the Core directly, you can set |
@lingol I see, thanks. It would work out in my case if I could use the MMKV library on Android from a C++ file (cpp-adapter, with So in this cpp-adapter I want to call MMKV stuff: Unfortunately I'm not that experienced with the Android JNI build system and CMake, so I couldn't figure out how to correctly install MMKV and have it imported in my C++ adapter. Do you maybe know how that could work? I tried to add the MMKV dependency to my build.gradle, but that only made MMKV available in the Java "world", there were no headers available for the C++ adapter. I also tried to add this to my cmake_minimum_required(VERSION 3.4.1)
set (CMAKE_VERBOSE_MAKEFILE ON)
set (CMAKE_CXX_STANDARD 11)
add_library(cpp
SHARED
cpp-adapter.cpp
)
include_directories(
../cpp
)
find_library(
MMKV
mmkv-static
)
target_link_libraries(
cpp
${MMKV}
) but that gave me the following error: |
Well, you got to learn something about CMake & NDK development. Everything you ask, they are already inside the MMKV repo. You just need to learn to know where to look for them. |
A little hint, you should get started by opening the |
@lingol you're right, I need to learn more about the NDK build system, I'm coming from the iOS world. Let me rephrase my question then; Does the
My Files
I appreciate any help. ❤️ |
JFYI: I have published my project at react-native-mmkv if you want to mention that in this project's README so users know there is an unofficial library for React Native available. It currently works by using git submodules, which of course requires me to update it everytime an important commit lands. Using MMKV as a gradle dependency would solve this issue, but afaik this requires you to add Prefabs to the gradle artifact. (see the Android Guide I linked in the comment above) |
I'm glad that you figure it out with something working. As for your concern about the git submodule. Here's the thing. You get two options.
|
If you like to try the MMKV C methods set for Flutter, there's one thing you should keep in mind. The C methods are intended for internal use only. There are no public headers declare about them. And they could be changed in the future without further notice. |
Hey @lingol - I'm revisiting this topic right now and I am wondering why on Apple, strings and buffers are not just supported as is? The Lines 278 to 304 in 33003ea
I feel like the Thank you! |
It's mainly because ObjC already has Adding the C++ part back in iOS is OK. But it will increase the binary size a bit. And it might force iOS users to rename an ObjC file (.m) to an ObjC++ file (.mm) when they |
I see, well in my case I'm not using the ObjC classes, since I bridge MMKV to JavaScript/React Native, and that's all C++ types (std::string, raw buffers, ...), so the additional NS.. conversion step could ideally be avoided. Would you be interested in a PR where I expose those C++ specific methods? only under a |
Don't bother. At this time, as long as you don't support iOS 12 (well maybe even lower), you can just use MMKVCore instead. |
Well yea, but MMKVCore does not expose the |
Wait the whole Line 23 in 33003ea
So I guess the std::string , MMBuffer , etc. methods are all available, even if imported in Objective-C (since you import it in libMMKV.mm .
So I guess I'm talking about something like this: #1260 |
One more thing, if all you care about is the C++ interface, defining |
Yea, I just played around with that more and I think you're right. My PR probably isn't going to be a full solution anyways, since keys are still NSString, etc. So let's close that PR, and I'll just roll with |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Hi!
I'm developing a wrapper library for MMKV which will be used for the cross-platform framework React Native. Ideally I want to have a single Wrapper <-> MMKV layer, written in C++ which works on Android and iOS. (That's because I'm using JSI and I am somewhat forced to use a shared C++ codebase, so no platform dependent code in Java or ObjC)
I tried to use the
MMKVCore
pod instead ofMMKV
:But that somehow still imports Obj-C code (NSObject, ..), because I am getting those errors:
Is there a way that I can use MMKV-Core directly to share code between Android and iOS with a single C++ code-base?
Thanks!
The text was updated successfully, but these errors were encountered: