3

I use mapbox-gl (https://github.com/mapbox/mapbox-gl-native).

I built libmapbox-gl.so (arch armeabi-v7a) using make-android.

Test app in Android Studio works correctly.

Then in the Qt project tried to link this library in myproject.pro file:

contains(ANDROID_TARGET_ARCH,armeabi-v7a)
 { 
   ANDROID_EXTRA_LIBS = \
   $$PWD/../Desktop/mapbox-gl-native/build/android-arm-v7/Release/lib.target/libmapbox-gl.so
 }

Project builds correctly. But when I try to run app on device, app crashes. I think, app can't find this library.

How to properly connect the library and what could be the problem?

4

1 回答 1

2

Below are the key parts to get it to work in the context of a Gradle activity.

myproject.pro

# ...

android {
    QT += androidextras

    # Default rules for deployment.
    include(deployment.pri)

    DISTFILES += \
        android/gradle/wrapper/gradle-wrapper.jar \
        android/AndroidManifest.xml \
        android/res/values/libs.xml \
        android/build.gradle \
        android/gradle/wrapper/gradle-wrapper.properties \
        android/gradlew \
        android/gradlew.bat \
        android/src/com/example/myproject/MySubclassOfQtActivity.java

    ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android
}

# ...

deployment.pri

android-no-sdk {
    target.path = /data/user/qt
    export(target.path)
    INSTALLS += target
} else:android {
    x86 {
        target.path = /libs/x86
    } else: armeabi-v7a {
        target.path = /libs/armeabi-v7a
    } else {
        target.path = /libs/armeabi
    }
    export(target.path)
    INSTALLS += target
} else:unix {
    isEmpty(target.path) {
        qnx {
            target.path = /tmp/$${TARGET}/bin
        } else {
            target.path = /opt/$${TARGET}/bin
        }
        export(target.path)
    }
    INSTALLS += target
}

export(INSTALLS)

Gradle searches and finds the libs properly in the libs directory and it gets bundle properly by Qt creator during the deployment.

Examining build.gradle it has: android > sourcesets > main > jniLibs.srcDirs = ['libs']

Hope that helps.

于 2015-08-16T05:27:56.433 回答