This guide describes how to include a third-party library in your application package. There are many libraries which provide APIs that may be useful to your application.
This guide assumes that the androiddeployqt tool is used for constructing the deployment package. When using Qt Creator for building and deploying, androiddeployqt is used behind the scenes, so this also applies to development with Qt Creator. Explaining how to access the library's APIs after being included in the project is not in the scope of this guide. For more information, see Extending Qt with Android Facilities .
The very first thing you need to do is to copy the library files into your project. The contents of the library have to be copied without modifications into the packaging directory, i.e. into the path set by
QT_ANDROID_PACKAGE_SOURCE_DIR
. By default, it's a directory named
android
under the root of the project source. For more information, see
Android 库
.
If you are using Qt Creator, you can quickly set up the packaging directory structure by selecting Projects > 构建 > Build Android APK > Create Templates . This creates a directory for your Android package customizations . Copy the library directory into "<target_src>/android/libs/" .
To add native shared libraries, you can use CMake's property
QT_ANDROID_EXTRA_LIBS
or
qmake
's
ANDROID_EXTRA_LIBS
which enables bundling the library into the Android package.
By default, Qt for Android uses can use
.jar
or
.aar
libraries that are found in the path
"<target_src>/android/libs/"
. Qt has the following rule in
build.gradle
file that is part of
the Gradle files
used by Android build:
dependencies { implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar']) ... }
Having a library called
CustomLibrary
, similar to the previous approach, copy the library project to your packaging directory
"<target_src>/android/libs/"
, then create a file
settings.gradle
with the following content:
include ':libs:CustomLibrary'
Then, add the dependency to
build.gradle
file inside the
dependencies
块:
dependencies { ... implementation project(":libs:CustomLibrary") ... }
For more information on adding libraries to an Android project, see Add build dependencies Android documentation .
Android 服务 发布到 Google Play