简体   繁体   English

在 Qt 中使用 aar 库

[英]Using aar Library with Qt

is it possible to use a Android Studio Library (aar file) in a Qt app?是否可以在 Qt 应用程序中使用 Android Studio 库(aar 文件)?

The problem is, that I want to implement a mobile App with Qt, but there is only a library for Android Studio.问题是,我想用 Qt 实现一个移动应用程序,但只有一个 Android Studio 库。 Is it possible to include the library in the Qt project or have I to write a wrapper class for it?是否可以将库包含在 Qt 项目中,或者让我为它编写一个包装类?

If I have to implement a wrapper, do I have to use the JNI and are there any examples for using it with C++ and a Java lib?如果我必须实现一个包装器,我是否必须使用 JNI,是否有将它与 C++ 和 Java 库一起使用的示例?

I found the answer, that worked for me.我找到了答案,这对我有用。

First you have to unzip the aar file, so you can get your jar library file.首先,您必须解压缩 aar 文件,以便获得 jar 库文件。 Then you can follow the instructions in this link to include the library to your apk: http://doc.qt.io/qt-5/android3rdpartylibs.html然后您可以按照此链接中的说明将库包含到您的 apk 中: http : //doc.qt.io/qt-5/android3rdpartylibs.html

When you have finished this, you have to implement your own Java wrapper class to interact with the library.完成此操作后,您必须实现自己的 Java 包装器类以与库进行交互。 Therfore you have to use the QAndroidJniObject class from Qt.因此,您必须使用 Qt 中的 QAndroidJniObject 类。 Here are more information about it.这里有更多关于它的信息。 http://doc.qt.io/qt-5/qandroidjniobject.html http://doc.qt.io/qt-5/qandroidjniobject.html

You could also have a look at this example, where they use their own java class.你也可以看看这个例子,他们使用自己的java类。 http://doc.qt.io/qt-5/qtandroidextras-notification-example.html http://doc.qt.io/qt-5/qtandroidextras-notification-example.html

You can add .aar files directly to your project您可以将 .aar 文件直接添加到您的项目中

In gradle file add .aar folder to dependencies在 gradle 文件中将 .aar 文件夹添加到依赖项

compile project(':myAarFolder1.1')

and include it in gradle.settings并将其包含在 gradle.settings 中

include ':myAarFolder1.1'

the aar file location in my project is like this我项目中的aar文件位置是这样的

android/myAarFolder1.1/.aar
android/myAarFolder1.1/build.gradle

android/myAarFolder1.1/build.gradle file content android/myAarFolder1.1/build.gradle 文件内容

configurations.maybeCreate("default")
artifacts.add("default", file('myAarFolder1.1.aar'))

Ok incase anyone else comes across this I figured it out.好的,以防万一其他人遇到这个我想通了。

If you don't already have an android source folder add one by inserting this into your .pro file如果您还没有 android 源文件夹,请通过将其插入到您的 .pro 文件中来添加一个

android {
   ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android-sources
}

Here is an example file structure:这是一个示例文件结构:

project/android-sources
project/android-sources/settings.gradle
project/android-sources/build.gradle
project/android-sources/LibraryFolder
project/android-sources/LibraryFolder/Library.aar
project/android-sources/LibraryFolder/build.gradle

You might have to get your build.gradle file from ../build-Android/android-build/build.gradle and copy it into project/android-sources/ if it doesn't already exist.您可能需要从../build-Android/android-build/build.gradle获取 build.gradle 文件并将其复制到project/android-sources/如果它不存在。

Insert this into your build.gradle file within dependencies { }将此插入到您的 build.gradle 文件中的依赖项 { }

api project(':LibraryFolder')

Insert this into your settings.gradle file at the bottom将其插入到底部的 settings.gradle 文件中

include ':LibraryFolder'

Create the build.gradle file inside LibraryFolder and insert:在 LibraryFolder 中创建 build.gradle 文件并插入:

configurations.maybeCreate("default")
artifacts.add("default", file('Library.aar'))

and lastly if the library you are adding has other 3rd party dependencies you will have to add them to project/android-sources/build.gradle最后,如果您添加的库具有其他 3rd 方依赖项,则必须将它们添加到project/android-sources/build.gradle

For example I was adding ImagePicker and had to insert the below lines inside dependencies { } but above api project(':LibraryFolder')例如,我正在添加ImagePicker并且必须在依赖项 { } 中插入以下行,但在api project(':LibraryFolder')之上

implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'com.github.bumptech.glide:glide:4.9.0'

from the library's source图书馆的来源

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM