Skip to content
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

Clarification on Android/iOS use #16

Open
Dreamykass opened this issue Oct 1, 2021 · 12 comments
Open

Clarification on Android/iOS use #16

Dreamykass opened this issue Oct 1, 2021 · 12 comments
Labels
enhancement New feature or request

Comments

@Dreamykass
Copy link

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 #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 Dreamykass added the enhancement New feature or request label Oct 1, 2021
@greenrobot
Copy link
Member

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
Copy link

srdw commented Nov 20, 2021

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
Copy link
Author

Dreamykass commented Nov 21, 2021

@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
Copy link

srdw commented Nov 22, 2021

@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
Copy link
Author

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

@srdw
Copy link

srdw commented Nov 22, 2021

@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
Copy link

srdw commented Nov 28, 2021

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
Copy link
Contributor

vaind commented Nov 28, 2021

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
Copy link

srdw commented Nov 28, 2021

@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
Copy link
Contributor

vaind commented Nov 28, 2021

Nothing to be sorry about

@mohammadjalalis
Copy link

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
Copy link

srdw commented Feb 22, 2022

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
}
	

@objectbox objectbox deleted a comment from paulocoutinhox Jun 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants