Replies: 19 comments
-
To clarify those errors a bit, when importing the |
Beta Was this translation helpful? Give feedback.
-
I don't recommend using the C++ Core directly for mobile cross-platform frameworks. You should wrap on top of MMKV for iOS & MMKV for Android. That's how we support the flutter platform. |
Beta Was this translation helpful? Give feedback.
-
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 ! |
Beta Was this translation helpful? Give feedback.
-
If you really really want to use the Core directly, you can set |
Beta Was this translation helpful? Give feedback.
-
@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: |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
A little hint, you should get started by opening the |
Beta Was this translation helpful? Give feedback.
-
@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. ❤️ |
Beta Was this translation helpful? Give feedback.
-
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) |
Beta Was this translation helpful? Give feedback.
-
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.
|
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
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! |
Beta Was this translation helpful? Give feedback.
-
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 |
Beta Was this translation helpful? Give feedback.
-
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 |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
Well yea, but MMKVCore does not expose the |
Beta Was this translation helpful? Give feedback.
-
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 |
Beta Was this translation helpful? Give feedback.
-
One more thing, if all you care about is the C++ interface, defining |
Beta Was this translation helpful? Give feedback.
-
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 |
Beta Was this translation helpful? Give feedback.
-
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!
Beta Was this translation helpful? Give feedback.
All reactions