Uploaded image for project: 'Qt Creator'
  1. Qt Creator
  2. QTCREATORBUG-11237

Android shared library deployment does not account for versioning

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Not Evaluated
    • Resolution: Duplicate
    • Affects Version/s: Qt Creator 3.0.0
    • Fix Version/s: None
    • Component/s: Android Support
    • Labels:
      None
    • Environment:
      Kubuntu 13.10

      Description

      I am trying to include a shared library with my android app. I have built the library with the NDK and have added it both by using Add Library in the UI and under deployment configurations added the library as an additional library.

      My pro file looks like:

      AndroidUI.pro
      # Add more folders to ship with the application, here
      folder_01.source = qml/AndroidUI
      folder_01.target = qml
      DEPLOYMENTFOLDERS = folder_01
      
      # Additional import path used to resolve QML modules in Creator's code model
      QML_IMPORT_PATH =
      
      # The .cpp file which was generated for your project. Feel free to hack it.
      SOURCES += main.cpp
      
      # Installation path
      # target.path =
      
      # Please do not modify the following two lines. Required for deployment.
      include(qtquick2controlsapplicationviewer/qtquick2controlsapplicationviewer.pri)
      qtcAddDeployment()
      
      ANDROID_EXTRA_LIBS = ../../android-ext/lib/libopus.so
      
      win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../android-ext/lib/release/ -lopus
      else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../android-ext/lib/debug/ -lopus
      else:unix: LIBS += -L$$PWD/../../android-ext/lib/ -lopus
      
      INCLUDEPATH += $$PWD/../../android-ext/include/opus
      DEPENDPATH += $$PWD/../../android-ext/include/opus
      

      The program itself is just the hello world program which I am using to see how I add a shared library. So very few changes and it looks like this:

      main.cpp
      #include "qtquick2controlsapplicationviewer.h"
      #include "opus.h"
      #include "qdebug.h"
      #include "qlibrary.h"
      
      int main(int argc, char *argv[])
      {
          Application app(argc, argv);
      
          QtQuick2ControlsApplicationViewer viewer;
          viewer.setMainQmlFile(QStringLiteral("qml/AndroidUI/main.qml"));
          qDebug() << "Hello world!";
          QLibrary* library = new QLibrary("libopus.so");
          typedef const char* (*MyPrototype)();
          MyPrototype myFunction = (MyPrototype) library->resolve("opus_get_version_string");
          qDebug() << myFunction();
          qDebug() << opus_get_version_string();
      
          viewer.show();
      
          return app.exec();
      }
      

      The program compiles and deploys fine but when run on the emulator it errors out straight away as it is looking for the wrong version of the library.

      E/AndroidRuntime(13463): FATAL EXCEPTION: main
      E/AndroidRuntime(13463): Process: org.qtproject.example.AndroidUI, PID: 13463
      E/AndroidRuntime(13463): java.lang.UnsatisfiedLinkError: dlopen failed: could not load library "libopus.so.0" needed by "libAndroidUI.so"; caused by library "libopus.so.0" not found

      QtCreator has in fact included the library in the apk but it choose just libopus.so hence why it could not find libopus.so.0

      In the lib directory I linked to it has the following files

      lrwxrwxrwx  1 stuart stuart      16 Jan  8 17:37 libopus.so -> libopus.so.0.5.0
      lrwxrwxrwx  1 stuart stuart      16 Jan  8 17:37 libopus.so.0 -> libopus.so.0.5.0
      -rwxr-xr-x  1 stuart stuart 1170652 Jan  8 17:37 libopus.so.0.5.0

      libopus.so and libopus.so.0 are just symlinks to libopus.so.0.5.0. QtCreator has correctly copied the file into the apk not the symlink but the referencing is wrong.

      I know the library is fine as if I comment out the LIBS stuff in the pro file and the function call and use QLibrary then it works and resolves and I get the expected output from the function call.

      Using QLibrary could be a work around in the meantime but is a bit clunky due to the typedefs and as the library is bundled there is no need for the dynamic loading.

      Any better workarounds until this bug is fixed?

        Attachments

          Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            Activity

              People

              Assignee:
              dt Daniel Teske
              Reporter:
              stuartmarsden Stuart Marsden
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Gerrit Reviews

                  There are no open Gerrit changes