Building android app on Qt using additional librar

2019-06-25 23:31发布

问题:

Hi I am trying to port an OpenGL desktop app to android. I have no knowledge of android development so am depending on Qt Creator to package the app. As part of the setup, I have invoked 'make-standalone-toolchain' script in android ndk with following settings

--platform=android-21 
--toolchain=arm-linux-androideabi-4.9 
--system=linux-x86_64

Then I used android-cmake and passed it the path of my newly created standalone-toolchain, which created libassimp.so, libassimp.so.3, and libassimp.so.3.1.1(ln) inside my assimp directory tree.

I passed the libassimp.so path to Qt creator project build menu under 'additional libraries'. However, on deploying the app on android, it crashes with error:

 dlopen("/data/app/org.qtproject.example.a3dqtquick-2/lib/arm/lib3dqtquick.so", RTLD_LAZY) failed: dlopen failed: could not load library "libassimp.so.3" needed by "lib3dqtquick.so"; caused by library "libassimp.so.3" not found

I can even see the libassimp.so (not libassimp.so.3) file inside the project build directory at ../android-build/libs/armeabi-v7a.

Not sure where to go from here, manually placing libassimp.so.3 at this location does not sort out the problem. Thanks for reading. I will add further info on your feedback . please forgive any info deficiency as this is my first experiment with android.

Following is the deployment-settings.json file

  "description": "This file is generated by qmake to be read by androiddeployqt and should not be modified by hand.",
   "qt": "/home/ubashir/programs/Qt/5.4/android_armv7",
   "sdk": "/home/ubashir/programs/android-sdk-linux",
   "sdkBuildToolsRevision": "21.1.2",
   "ndk": "/home/ubashir/programs/android-ndk-r10d",
   "toolchain-prefix": "arm-linux-androideabi",
   "tool-prefix": "arm-linux-androideabi",
   "toolchain-version": "4.9",
   "ndk-host": "linux-x86_64",
   "target-architecture": "armeabi-v7a",
   "qml-root-path": "/home/ubashir/code/3dqtquick",
   "application-binary": "/home/ubashir/code/3dqtquickAndroid/lib3dqtquick.so" 

UPDATE:

I have now tried this.. replace all links to assimp.so.3.1.1 with copies of the latter so now my library libassimp.so.3 is a file instead of link to libassimp.so.3.1.1. I manually added libassimp.so.3 to my project subfolder android/libs/aremabi-v71 --- no good. I confirm that my build directory shows all libassimp files as I manually added them so presumably they are being deployed but the error remains :

failed: dlopen failed: could not load library "libassimp.so.3" needed by "lib3dqtquick.so".

As outlined here http://webmail.dev411.com/p/gg/android-ndk/1386vger6e/use-assimp-c-library-in-ndk-ld-error-obj-local-armeabi-v7a-libassimp-so-incompatible-target-for-use-with-vuforia

I even edited the link.txt file after running cmake on my assimp build directory for android, altering the entry -soname,libassimp.so.3 with -soname,libassimp.so but it still creates libassimp.so.3.1.1 with its two links , i.e., libassimp.so.3 and libassimp.so. So still stuck..

回答1:

I ran into the same problem with a shared library I built with CMake for and Android project. I found a way to fix it. There might be a cleaner solution if you were more familiar with CMake.

Search through the CMakeLists.txt file(s) for "SOVERSION" and "SET_TARGET_PROPERTIES()"

In the SET_TARGET_PROPERTIES() routine comment out the lines for VERSION and SOVERSION as follows

SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES                # create *nix style library versions + symbolic links
    DEFINE_SYMBOL DSO_EXPORTS
        #   VERSION ${PROJECT_VERSION}
        #   SOVERSION ${PROJECT_SOVERSION}
    CLEAN_DIRECT_OUTPUT 1                   # allow creating static and shared libs without conflicts
    OUTPUT_NAME "${PROJECT_NAME}${PROJECT_DLLVERSION}"  # avoid conflicts between library and binary target names
)

Then rerun the configure and generate steps in CMake and rebuild the target. This should give you a .so without any version numbers.



回答2:

I'll suggest you to take a look at the solution I've found to my problem (that is very similar to yours):

libgdal.so android error: could not load library "libgdal.so.1"

Hope this helps.