objectbox-c icon indicating copy to clipboard operation
objectbox-c copied to clipboard

Clarification on Android/iOS use

Open Dreamykass opened this issue 4 years ago • 12 comments

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.

Dreamykass avatar Oct 01 '21 13:10 Dreamykass

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.

greenrobot avatar Oct 01 '21 17:10 greenrobot

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.

srdw avatar Nov 20 '21 20:11 srdw

@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).

Dreamykass avatar Nov 21 '21 21:11 Dreamykass

@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?

srdw avatar Nov 22 '21 06:11 srdw

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

Dreamykass avatar Nov 22 '21 15:11 Dreamykass

@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 avatar Nov 22 '21 17:11 srdw

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!

srdw avatar Nov 28 '21 16:11 srdw

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.

  • C++ - you can pass it via the Options class https://objectbox.io/docfiles/c/current/classobx_1_1Store_1_1Options.html
  • C - obx_opt_diretory() - https://objectbox.io/docfiles/c/current/group__c.html#ga20c0fc89d5e3c0c92627083729a6a2c7

vaind avatar Nov 28 '21 18:11 vaind

@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!

srdw avatar Nov 28 '21 18:11 srdw

Nothing to be sorry about

vaind avatar Nov 28 '21 18:11 vaind

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?

mohammadjalalis avatar Feb 22 '22 07:02 mohammadjalalis

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
}
	

srdw avatar Feb 22 '22 20:02 srdw