6

Hi all and Sorry in advance for asking this question, but after five days of searching on stackoverflow and doing google-engineering I still got no answer for my question:

I would like to include several *.jar files to my project that shall be used by my android app after Qt compiled it.

Here is my environment:

  • Installed Qt Creator 3.2.1(exe, not compiled from sources)
  • main.cpp (starting Qt-Part)
  • android/MainActivity.java (starting simple "Hello world" stuff and shall include different classes provided by the .jars (google-api-client-1.19.0.jar google-api-client-android-1.19.0.jar google-http-client-1.19.0.jar google-http-client-android-1.19.0.jar google-http-client-jackson-1.19.0.jar google-oauth-client-1.19.0.jar jackson-core-asl-1.9.13.jar jsr305-1.3.9.jar)
  • android/AndroidManifest.xml
  • android/libs containing the required .jars

After googling for that problem, I tried almost everything, getting the same result each time: the .jars are not found for the android application or the build process did not work:

[javac] C:\workspaces\qt_android\build-GsQt-Android\android-build\src\com\gservice\MainActivity.java:14: error: package com.google.android.gms.common does not exist
[javac] import com.google.android.gms.common.ConnectionResult;
[javac]                                     ^
[javac] C:\workspaces\qt_android\build-GsQt-Android\android-build\src\com\gservice\MainActivity.java:15: error: package com.google.android.gms.common.api does not exist
[javac] import com.google.android.gms.common.api.GoogleApiClient;
[javac]                                         ^\MainActivity.java:15: error: package com.google.android.gms.common.api does not exist

and so on, for all of the eight jars that shall be included.

Here are the things I tried to include them:

  • created a folder within android, called "libs" and put my jars into it. After building the project, the folder and the jars have been copied to the build directory. By not to the device as it seems.
  • included them as simple other files like the AndroidManifest and the MainActivity:
OTHER_FILES += \
android/libs/google-api-client-1.19.0.jar \
android/libs/google-api-client-android-1.19.0.jar \
android/libs/google-api-services-gmail-v1-rev2-1.18.0-rc.jar \
android/libs/google-http-client-1.19.0.jar \
android/libs/google-http-client-android-1.19.0.jar \
android/libs/google-http-client-jackson-1.19.0.jar \
android/libs/google-oauth-client-1.19.0.jar \
android/libs/jackson-core-asl-1.9.13.jar \
android/libs/jsr305-1.3.9.jar \
android/AndroidManifest.xml \
android/src/com/gservice/MainActivity.java \
  • trying the assets-inclusion in the .pro file:
LIBS_INSTALL_PATH=/assets/libs

libraries.path=android/libs libraries.files += google-api-client-1.19.0.jar google-api-client-android-1.19.0.jar google-http-client-1.19.0.jar google-http-client-android-1.19.0.jar google-http-client-jackson-1.19.0.jar google-oauth-client-1.19.0.jar jackson-core-asl-1.9.13.jar jsr305-1.3.9.jar libraries.depends += FORCE INSTALLS += libraries

  • creating a libraries.qrc file and include this via RESOURCES += libraries.qrc in the .pro file. libraries.qrc:
<RCC>
<qresource prefix="/libs">
    <file>android/libs/google-api-client-1.19.0.jar</file>
    <file>android/libs/google-api-client-android-1.19.0.jar</file>
    <file>android/libs/google-api-services-gmail-v1-rev2-1.18.0-rc.jar</file>
    <file>android/libs/google-http-client-1.19.0.jar</file>
    <file>android/libs/google-http-client-android-1.19.0.jar</file>
    <file>android/libs/google-http-client-jackson-1.19.0.jar</file>
    <file>android/libs/google-oauth-client-1.19.0.jar</file>
    <file>android/libs/jackson-core-asl-1.9.13.jar</file>
    <file>android/libs/jsr305-1.3.9.jar</file>
</qresource>
</RCC>
  • trying with qmake (which returns an error, that rcc file's not found) "rcc -binary google-api-client-1.19.0.jar -o google-api-client-1.19.0.rcc" as additional parameter

... I really do not know what to do next, all of my Android-configurations (JDK, SDK, NDK, Ant) are at the correct place and are accessable, JAVA_HOME var and ANT var are set.

Two scentences at the end: the code I want to include for Android is a Google+ authentication app I already created with the Android ADT and that works fine. I shall transfer that working components into the build environment of Qt.

Thanks in advance for reading that looooong description and for helping me getting that solved!

Loyd

Loyd Schnitzel
  • 111
  • 1
  • 5

2 Answers2

5

SOLUTION:

There IS a way to include and use .jar Files with Android and Qt. And it is certainly the easiest way one can imagine:

  1. Open the android folder of your Qt project
  2. Create a folder called "libs" (same level as folder "src" and "AndroidManifest.xml")
  3. Put the *.jar files you want to use into the libs folder
  4. Import them within your android-java file as usual

That's it. No adaption of Project.pro or main.qrc needed and also no need to create a .properties file for android or similar.

Loyd Schnitzel
  • 111
  • 1
  • 5
  • You're welcome =) I thought, Qt's new version got a documentation-update, but it is still a bit fragmentary ;-) – Loyd Schnitzel Jul 07 '15 at 12:31
  • how to #include it to c++ or qml? – mohammad alabid Apr 20 '16 at 08:17
  • @mohammadalabid, maybe this solution can help you with C++ http://stackoverflow.com/questions/8850202/use-jar-file-in-c-c For the usage within qml I have no idea, since this is more a describing than a programming language... – Loyd Schnitzel Apr 27 '16 at 09:46
  • I don't understand, in your question you say that `android/libs containing the required .jars` don't work, and on your answer you're saying that creating a libs folder containing the jars is working ? I'm facing the same issue, and having my jars files in android/libs doesn't work. (the jar files are present in the android package build folder, but when compiling it tells that package does not exist) – saperlipopette Nov 15 '18 at 09:26
0

OTHER_FILES is for human consumption only. It is only used by Qt Creator's project explorer to include the files in the tree. It's not used in the build process at all.

The Qt resource system (QRC) is only usable from QFile, the Android VM has no knowledge of those "files".

Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313