[Interest] Including Qt Quick 2 extension plugin in Android App

René Hansen renehh at gmail.com
Fri Oct 5 12:57:26 CEST 2018


I don't have the problem if I just want a plain shared library, in that
case just bundling the .so with ANDROID_EXTRA_LIBS works fine.

Isolating code into an extension plugin with both QML components and Qt
classes and using that in separate apps is my goal.

If anyone has a working example + build and package process somewhere, I'd
love to see it.

I simply don't get how it's supposed to work. Most SO answers etc. seem to
point to people giving up and just copying stuff directly into their apps.
I just can't get myself to believe there isn't a better way to do this.


/René

On Thu, 4 Oct 2018 at 23:37 Jérôme Godbout <godboutj at amotus.ca> wrote:

> Not sure if it might help, but I had some problems with bundling some lib
> with my application and I end up with this in my project:
> android/lib   // for my .so library, note the lib without s here
> android/libs // for my .jar library
>
> Then I add those lib into the extra libs into my .pro:
>
> ANDROID_EXTRA_LIBS += \
>
>             $$PWD/android/lib/libcrypto.so \
>
>             $$PWD/android/lib/libssl.so
>
>
> Seem like the android/libs folder is somehow special for qmake.
>
>
> I also attached the copy android sources, if you every need to have .pri that want to include android lib on his own,
>
> this is a work derivated from Luke Vear which I talk to on slack when I was trying to achieve this.
>
>
> Including Android lib and .jars from multiple .pri is a huge pain, avoid it unless you want to use something like the attached files.
>
> How to use the atatched file:
>
>
> include(CopyAndroidSources.pri)
>
> defineReplace(androidPathMaker) {
>
>         for(a, $$3) {
>
>             result += $$1/$$2/$${a}
>
>         }
>
>         return($$result)
>
>     }
>
>     defineReplace(androidSourceMaker) {
>
>          return($$copyAndroidSources($$1, $$2, $$androidPathMaker($$3, $$4, $$5)))
>
>     }
>
>
> SOURCES_ANDROID_WORKPAD_TECHKNOWSERV = \
>
>         UhfReader.java
>
>     QMAKE_EXTRA_TARGETS += $$androidSourceMaker("WorkpadTechKnowServ_Android_Sources", "src/com/amotus/workpad/techknowserv", $$clean_path($$PWD), "android-src/src/com/amotus/workpad/techknowserv", SOURCES_ANDROID_WORKPAD_TECHKNOWSERV)
>
>
>     LIB_ANDROID_WORKPAD_TECHKNOWSERV = \
>
>         libpda.so \
>
>     QMAKE_EXTRA_TARGETS += $$androidSourceMaker("WorkpadTechKnowServ_Android_Lib", "lib", $$clean_path($$PWD), "android-src/lib", LIB_ANDROID_WORKPAD_TECHKNOWSERV)
>
>
> ANDROID_EXTRA_LIBS += \
>
>         $$clean_path($$PWD)/android/lib/libpda.so \
>
>
> SO you place everything into android-src and copy all the stuff into android when building the project, so multiple source can declare their own lib usage
>
>
> On Thu, 4 Oct 2018 at 16:39, René Hansen <renehh at gmail.com> wrote:
>
>> Hi everyone,
>>
>>
>> I can't seem to get the voodoo right on something that should be trivial.
>>
>> My use case is this; I have two Android apps, which uses similar logic
>> that I'd like to extract and share between them, in the form of an
>> extension plugin. Easy peasy right? Well, I just can't seem to figure it
>> out.
>>
>> In order to distill my understanding of how this is supposed to work I've
>> created a simple example in this repo:
>>
>> https://github.com/rhardih/app-with-extension-example
>>
>> All I've done is the following:
>>
>> 1. Generated the default Qt Quick Controls 2 Swipe app.
>> 2. Generated the default Qt Quick 2 extension plugin.
>> 3. Added a custom QML invokable method, "foo()" on the default "MyItem".
>> 4. Updated the App.pro file, and specified the extension's install path,
>> (Maybe incorrectly), to the QML_IMPORT_PATH
>>
>> I get the autocompletion inside QtCreator for "MyItem" and no import
>> errors in the editor, so something must be right.
>>
>> However... as soon as I run the App, i get:
>>
>> W libApp.so: (null):0 ((null)): QQmlApplicationEngine failed to load
>> component
>> W libApp.so: (null):0 ((null)): qrc:/main.qml:4 module
>> "com.mycompany.qmlcomponents" is not installed
>>
>> The extension build folder looks like this after a build:
>>
>> ├── Makefile
>> ├── android-build
>> │   ├── Users
>> │   │   └── rene
>> │   │       └── Code
>> │   │           └── Qt
>> │   │               └── 5.11.1
>> │   │                   └── android_armv7
>> │   │                       └── qml
>> │   │                           └── com
>> │   │                               └── mycompany
>> │   │                                   └── qmlcomponents
>> │   │                                       └── qmldir
>> │   └── libs
>> │       └── armeabi-v7a
>> │           └── libExtension.so
>> ├── extension_plugin.o
>> ├── libExtension.so
>> ├── moc_extension_plugin.cpp
>> ├── moc_extension_plugin.o
>> ├── moc_myitem.cpp
>> ├── moc_myitem.o
>> ├── moc_predefs.h
>> ├── myitem.o
>> └── qmldir
>>
>> Even so, libExtension.so isn't included in the .apk after building the
>> app. I can get it included by adding ANDROID_EXTRA_LIBS += <path
>> to>/libs/armeabi-v7a/libExtension.so, to App.pro, but that doesn't change
>> the above error.
>>
>> I've tried pointing ANDROID_EXTRA_PLUGINS to various locations of the
>> extension's install folder as well, but that just seems to dump everything
>> underneath the specified path, directly into assets...
>>
>> Can anyone tell me, how on earth is this supposed to work? Am I just
>> using the wrong paths, or am I missing something fundamental here?
>>
>>
>> /René Hansen
>>
> _______________________________________________
>> Interest mailing list
>> Interest at qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/interest
>>
>
>
> --
>
>
>
> RAPPROCHEZ LA DISTANCE
>
>
> *Jérôme Godbout*Senior Software Developer
>
> *p:* +1 (418) 800-1073 <(418)%20800-1073> ext.:109
>
> *m:* +1 (581) 777-0050 <(581)%20777-0050>
>
> amotus.ca <http://www.amotus-solutions.com/>
> statum-iot.com
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20181005/f265431e/attachment.html>


More information about the Interest mailing list