objectbox / objectbox-c

C and C++ database for objects and structs
https://objectbox.io/
Apache License 2.0
211 stars 37 forks source link

Clarification on Android/iOS use #16

Open Dreamykass opened 3 years ago

Dreamykass commented 3 years ago

I'd love to use ObjectBox in a multi-platform Android/iOS app (C++, QT/QML stack), as it looks to be pretty much perfect for my use case. But. It is unclear to me if that is supported - the main library/project says that it is, but the C/C++ wrapper does not mention so, and there are no binaries on the releases page for Android or iOS.

There's https://github.com/objectbox/objectbox-c/issues/4, but in the replies, it is not clear to me what "Android APIs also include the C interface" means. Am I supposed to get the Java jars from the gradle repository, and those would expose the C interface?

So effectively, this is both a question, as well as a request for clarification in the readme/releases if ObjectBox can be used from Android and iOS. If yes, then a tutorial/tips on how to do so, would be very much appreciated.

greenrobot commented 3 years ago

Yes, there are improvements possible in the docs. TLDR: Android comes with a "double feature" lib, that has JNI and the native C API. For iOS, Swift even builds upon the C API, so this is possible too.

srdw commented 3 years ago

I also want to use objectbox-c in my Android/iOS app using C++/QT5/QML. According to greenrobot's comment there seems to be a way to do it, but I still don't understand it. I look forward to the documentation updates.

Dreamykass commented 3 years ago

@srdw Here I wrote a super simple example on how to do it: https://github.com/Dreamykass/bitsofkass/tree/master/cpp-qt/2021-10-02--qt-qml-objectbox-android

Basically, you just get the compiled binary for C, from the java lib from maven repository or whatever (I don't use Java).

srdw commented 3 years ago

@Dreamykass

Thanks a Lot. I'll check it out!

By the way, are you using the objectbox-swift(https://github.com/objectbox/objectbox-swift) Lib file to build the iOS version?

Dreamykass commented 3 years ago

@srdw Nah, sorry. (actually, we've gone with sqlite for this project, but we will keep objectbox in mind for future ones)

srdw commented 3 years ago

@Dreamykass

😄

(Using DeepL)

I'm also planning to use Sqlite if ObjectBox is not available.

It's a game application, and we will be storing a lot of logs in a database. I would like to use ObjectBox with Scalable and Superfast.

I'll also try to build on iOS!

srdw commented 2 years ago

Hi @greenrobot

(Using DeepL)

I'm testing ObjectBox-C combined with Swift library files. In iOS Simulator, both read/write work, but in iOS Device, I get the following Runtime Error.

[ERROR] Storage error "Operation not permitted" (code 1)

objectbox.hpp Outputs "can't open store" in the costractor of the Store class.

ObjectBox-Swift allows you to specify the DirectoryPath when initializing the Store, while the c/c++ interface does not seem to have such a specification.

If you could let me know how to handle this, that would be great!

vaind commented 2 years ago

ObjectBox-Swift allows you to specify the DirectoryPath when initializing the Store, while the c/c++ interface does not seem to have such a specification.

srdw commented 2 years ago

@vaind

I'm sorry. I just tried it and it worked.

The following code worked for me on Qt+iOS Device!

#ifdef Q_OS_IOS
obx::Store::Options options(create_obx_model());
options.directory(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation).append(“/objectbox").toStdString()));
obx::Store store(options);
#endif

thx!

vaind commented 2 years ago

Nothing to be sorry about

mohammadjalalis commented 2 years ago

I'm testing ObjectBox-C combined with Swift library files.

Hi @srdw , How do you add objectbox-swift library files with QT and use it in your application?

srdw commented 2 years ago

Hello @mohammadjalalis.

I'm using Qt + Felgo, so I'm using qmake. (If you are using cmake, you may need to do it differently)

I have added each of them to the pro file.

Source files objectbox.h objectbox.hpp

Library files (probably redundant. Path is also a local environment, so just a little reference)

macx {
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../objectbox/release/ -lObjectBoxCore-macOS
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../objectbox/debug/ -lObjectBoxCore-macOS
else:unix: LIBS += -L$$PWD/../../objectbox/ -lObjectBoxCore-macOS

INCLUDEPATH += $$PWD/../../objectbox
DEPENDPATH += $$PWD/../../objectbox

win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../../objectbox/release/libObjectBoxCore-macOS.a
else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../../objectbox/debug/libObjectBoxCore-macOS.a
else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../../objectbox/release/ObjectBoxCore-macOS.lib
else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../../objectbox/debug/ObjectBoxCore-macOS.lib
else:unix: PRE_TARGETDEPS += $$PWD/../../objectbox/libObjectBoxCore-macOS.a
}

iphonesimulator:CONFIG(iphonesimulator, iphoneos|iphonesimulator){
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../objectbox/release/ -lObjectBoxCore-iOS-sim
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../objectbox/debug/ -lObjectBoxCore-iOS-sim
else:unix: LIBS += -L$$PWD/../../objectbox/ -lObjectBoxCore-iOS-sim

INCLUDEPATH += $$PWD/../../objectbox
DEPENDPATH += $$PWD/../../objectbox

win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../../objectbox/release/libObjectBoxCore-iOS-sim.a
else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../../objectbox/debug/libObjectBoxCore-iOS-sim.a
else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../../objectbox/release/ObjectBoxCore-iOS-sim.lib
else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../../objectbox/debug/ObjectBoxCore-iOS-sim.lib
else:unix: PRE_TARGETDEPS += $$PWD/../../objectbox/libObjectBoxCore-iOS-sim.a
}

iphoneos:CONFIG(iphoneos, iphoneos|iphonesimulator){
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../objectbox/release/ -lObjectBoxCore-iOS
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../objectbox/debug/ -lObjectBoxCore-iOS
else:unix: LIBS += -L$$PWD/../../objectbox/ -lObjectBoxCore-iOS

INCLUDEPATH += $$PWD/../../objectbox
DEPENDPATH += $$PWD/../../objectbox

win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../../objectbox/release/libObjectBoxCore-iOS.a
else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../../objectbox/debug/libObjectBoxCore-iOS.a
else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../../objectbox/release/ObjectBoxCore-iOS.lib
else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../../objectbox/debug/ObjectBoxCore-iOS.lib
else:unix: PRE_TARGETDEPS += $$PWD/../../objectbox/libObjectBoxCore-iOS.a
}