Use existing windows project to create a dynamic library for iOS and Android?
-
I've created a project in Visual Studio (using Qt tools) on Windows. In windows, the 2 projects statically compile to form a single executable (one is dependent on the other).
Now I need to use 1 of the projects (containing business logic but No UI) and create dynamic libraries for iOS and Android, so they can be used by apps. I'm not sure how to create a library project that I can configure to build iOS and Android library (.so) without messing up existing VS project?
If I create a "Qt Class Library" project in Visual Studio and add code to export methods I want, would that be good enough? Then I can do all the development on Windows and just build iOS library on mac? AFAIK, I can build android library on Windows but the library would need to dynamically link with Qt framework?
-
Hi,
I currently don't know how that could be done from a VS perspective.
From a qmake perspective, you would create SUBDIRS based project were you have one sub-project to build your library and two others to build your applications using that library. You can achieve the same with cmake which I would recommend since it became the default build system for Qt 6 but have a bit less experience with.
I would recommend you do it this way even for your desktop project, you would have the benefit of having a library (static or shared) for all your platforms and it would just be a switch to change build types rather than having to pretty different projects that would serve the same purpose.
The other advantage of having your business logic in a library re-used by several applications is that you can more easily test it.
-
Using cmake does not preclude you from using VS. It provides you with a platform neutral project that you can reuse for Windows, Androïd and other.
-
I'm new to manually compiling code, only did it during school days before :) Is it easier to work with qmake or cmake, any benefit to moving to cmake for Qt5? Since I already have my project setup in VS, I just export .pro and .pri files and the files seems to have all the info needed. On the other hand, for cmake: https://doc.qt.io/qt-5/cmake-get-started.html it looks like I would have to manually create these files?
What if I keep working within VS, and whenever I need to do android/iOS builds (not much) I just export .pro/.pri files and build using qmake?
Assuming 3 projects, A = shared lib, B = win32 exe, C = new dynamic library for android/iOS, all of them in same directory i.e. not nested. How would I need to setup .pro file for C to only use A, and create dynamic library for Android? Also, on iOS create dynamic library for that platform?
Too many questions, but I'm completely new to these iOS and android platforms so getting confused.
-
Why would you need C in the first place since A is already a library ?
You can't have all three projects in one .pro file.
Subdirs is the correct solution.
-
@SGaist said in Use existing windows project to create a dynamic library for iOS and Android?:
Why would you need C in the first place since A is already a library ?
A is a C++ library with core features. C would create logic to initialize classes in A and also export C-style function methods that can be called easily from Flutter/Xamarin app code. C would also allow Flutter/Xamarin to register callback functions with it, so when A notifies C of an event, it will invoke the callback method in Flutter/Xamarin.@SGaist said in Use existing windows project to create a dynamic library for iOS and Android?:
You can't have all three projects in one .pro file.
Correct, each project has a separate .pro file.@SGaist said in Use existing windows project to create a dynamic library for iOS and Android?:
Subdirs is the correct solution.
https://wiki.qt.io/SUBDIRS_-_handling_dependencies - this?How do I get a SUBDIRS project to generate android library using qmake? do I have to use qmake in android folder of Qt? anything else?
-
If you want to build a project for Androïd, you need the Qt build for Androïd as well as the SDK and NDK. It's all explained in the Androïd Getting Started Guide.
-
@SGaist I've already followed the guide and setup Android environment. The problem is that at the end its shows how to build Android applications using Qt Creater. Whereas, I'm interested in building a shared library, primarily through commandline on windows. Can't figure out how to do that