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

Jérôme Godbout godboutj at amotus.ca
Thu Oct 4 23:37:43 CEST 2018


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 ext.:109

*m:* +1 (581) 777-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/20181004/8f3440c3/attachment.html>
-------------- next part --------------
# MIT License
#
# Copyright (c) 2018 Luke Vear
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
#
# Taken from https://github.com/lukevear/qmakeAndroidSourcesHelper
# commit e0e47e0d0f1b70bedcc9e31e9f8b217e027d3a54
#
# Modification is as follow
# 2018-06-01 JG remove the .gitignore section, not needed
# 2018-06-01 JG return with more export
# 2018-06-01 JG Add FORCE depends for created target

defineReplace(copyAndroidSources) {
    commandAlias = $$1
    targetDirectory = $$2
    sourceFiles = $$3

    # Ensure we were provided a valid alias for this command
    isEmpty(commandAlias) {
        error("copyAndroidSources requires a valid command alias as its first argument.")
    }

    # Ensure we were provided a valid target directory
    isEmpty(targetDirectory) {
        error("copyAndroidSources requires a valid target directory path as its second argument.")
    }

    # Ensure we were provide a valid set of source files
    isEmpty(sourceFiles) {
        error("copyAndroidSources requires a valid set of files as its third argument.")
    }

    # Make sure the command is run, TODO godboutj 2018-06-01, this should be depends on used files instead
    $${commandAlias}.depends += FORCE

    # Create the target directory
# Work around problem with Windows that cannot make or on command and syntaxt is not the same with Windows and other *nix system
contains(QMAKE_HOST.os, Windows) {
    $${commandAlias}.commands += $$escape_expand(\n\t)$(CHK_DIR_EXISTS) $$shell_path($$ANDROID_PACKAGE_SOURCE_DIR/$$targetDirectory) $(MKDIR) $$shell_path($$ANDROID_PACKAGE_SOURCE_DIR/$$targetDirectory)
} else {
    $${commandAlias}.commands += $$escape_expand(\n\t)$(CHK_DIR_EXISTS) $$shell_path($$ANDROID_PACKAGE_SOURCE_DIR/$$targetDirectory) || $(MKDIR) $$shell_path($$ANDROID_PACKAGE_SOURCE_DIR/$$targetDirectory)
}
    # Process each file that we were provided
    for(fileName, sourceFiles) {
        # Copy the file from the source directory to the target directory
        $${commandAlias}.commands += $$escape_expand(\n\t)$(COPY_FILE) $$shell_path($$fileName) $$shell_path($$ANDROID_PACKAGE_SOURCE_DIR/$$targetDirectory/$$basename(fileName))
    }

    # We need to make our new command globally available so that qmake can add it to the generated Makefile
    export($${commandAlias}.commands)
    export($${commandAlias}.depends)

    # To ensure our command is run before compilation occurs we add our command to the dependency tree of 'first' (creating the tree if required)
    isEmpty(first.depends) {
        first.depends = $(first) $${commandAlias}
        export(first.depends)
        return(first $${commandAlias})
    }
    first.depends += $${commandAlias}
    export(first.depends)
    return($${commandAlias})
}


More information about the Interest mailing list