3

is it possible to use a Android Studio Library (aar file) in a Qt app?

The problem is, that I want to implement a mobile App with Qt, but there is only a library for Android Studio. Is it possible to include the library in the Qt project or have I to write a wrapper class for it?

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?

C.Fabi
  • 81
  • 2
  • 8

3 Answers3

3

I found the answer, that worked for me.

First you have to unzip the aar file, so you can get your jar library file. Then you can follow the instructions in this link to include the library to your 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. Therfore you have to use the QAndroidJniObject class from Qt. Here are more information about it. http://doc.qt.io/qt-5/qandroidjniobject.html

You could also have a look at this example, where they use their own java class. http://doc.qt.io/qt-5/qtandroidextras-notification-example.html

C.Fabi
  • 81
  • 2
  • 8
  • After I unzip the aar file, I got "classes.jar" and other folders and files. Should I only include the "classes.jar" file to my Qt project? – Heidi Jun 09 '17 at 07:54
0

You can add .aar files directly to your project

In gradle file add .aar folder to dependencies

compile project(':myAarFolder1.1')

and include it in gradle.settings

include ':myAarFolder1.1'

the aar file location in my project is like this

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

android/myAarFolder1.1/build.gradle file content

configurations.maybeCreate("default")
artifacts.add("default", file('myAarFolder1.1.aar'))
mohammad alabid
  • 444
  • 7
  • 21
0

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 {
   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.

Insert this into your build.gradle file within dependencies { }

api project(':LibraryFolder')

Insert this into your settings.gradle file at the bottom

include ':LibraryFolder'

Create the build.gradle file inside LibraryFolder and insert:

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

For example I was adding ImagePicker and had to insert the below lines inside dependencies { } but above 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

Scott
  • 147
  • 1
  • 4
  • 11