Add Android Support libraries into the Qt project?



  • Hello,

    I am using JNI and trying to get my Qt project for Android to compile. But i get problems in my StartCameraActivity :

    10:50:35: Running steps for project CameraProjectJNIx...
    10:50:35: Configuration unchanged, skipping qmake step.
    10:50:35: Starting: "C:\Qt\Tools\mingw530_32\bin\mingw32-make.exe" 
    C:\Qt\5.10.1\android_armv7\bin\uic.exe ..\CameraProjectJNIx\mainwindow.ui -o ui_mainwindow.h
    C:\Users\Philip\AppData\Local\Android\Sdk\ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/bin/arm-linux-androideabi-g++ -c -D__ANDROID_API__=16 --sysroot=C:\Users\Philip\AppData\Local\Android\Sdk\ndk-bundle/sysroot -isystem C:\Users\Philip\AppData\Local\Android\Sdk\ndk-bundle/sysroot/usr/include/arm-linux-androideabi -isystem C:\Users\Philip\AppData\Local\Android\Sdk\ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include -isystem C:\Users\Philip\AppData\Local\Android\Sdk\ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/include -fstack-protector-strong -DANDROID -march=armv7-a -mfloat-abi=softfp -mfpu=vfp -fno-builtin-memmove -g -g -marm -O0 -std=gnu++11 -Wall -W -D_REENTRANT -fPIC -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_ANDROIDEXTRAS_LIB -DQT_CORE_LIB -I..\CameraProjectJNIx -I. -IC:\Qt\5.10.1\android_armv7\include -IC:\Qt\5.10.1\android_armv7\include\QtWidgets -IC:\Qt\5.10.1\android_armv7\include\QtGui -IC:\Qt\5.10.1\android_armv7\include\QtAndroidExtras -IC:\Qt\5.10.1\android_armv7\include\QtCore -I. -I. -IC:\Qt\5.10.1\android_armv7\mkspecs\android-g++ -o main.obj ..\CameraProjectJNIx\main.cpp
    C:\Users\Philip\AppData\Local\Android\Sdk\ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/bin/arm-linux-androideabi-g++ -c -D__ANDROID_API__=16 --sysroot=C:\Users\Philip\AppData\Local\Android\Sdk\ndk-bundle/sysroot -isystem C:\Users\Philip\AppData\Local\Android\Sdk\ndk-bundle/sysroot/usr/include/arm-linux-androideabi -isystem C:\Users\Philip\AppData\Local\Android\Sdk\ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include -isystem C:\Users\Philip\AppData\Local\Android\Sdk\ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/include -fstack-protector-strong -DANDROID -march=armv7-a -mfloat-abi=softfp -mfpu=vfp -fno-builtin-memmove -g -g -marm -O0 -std=gnu++11 -Wall -W -D_REENTRANT -fPIC -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_ANDROIDEXTRAS_LIB -DQT_CORE_LIB -I..\CameraProjectJNIx -I. -IC:\Qt\5.10.1\android_armv7\include -IC:\Qt\5.10.1\android_armv7\include\QtWidgets -IC:\Qt\5.10.1\android_armv7\include\QtGui -IC:\Qt\5.10.1\android_armv7\include\QtAndroidExtras -IC:\Qt\5.10.1\android_armv7\include\QtCore -I. -I. -IC:\Qt\5.10.1\android_armv7\mkspecs\android-g++ -o mainwindow.obj ..\CameraProjectJNIx\mainwindow.cpp
    C:\Users\Philip\AppData\Local\Android\Sdk\ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/bin/arm-linux-androideabi-g++ -D__ANDROID_API__=16 --sysroot=C:\Users\Philip\AppData\Local\Android\Sdk\ndk-bundle/sysroot -isystem C:\Users\Philip\AppData\Local\Android\Sdk\ndk-bundle/sysroot/usr/include/arm-linux-androideabi -isystem C:\Users\Philip\AppData\Local\Android\Sdk\ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include -isystem C:\Users\Philip\AppData\Local\Android\Sdk\ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/include -fstack-protector-strong -DANDROID -march=armv7-a -mfloat-abi=softfp -mfpu=vfp -fno-builtin-memmove -g -g -marm -O0 -std=gnu++11 -Wall -W -dM -E -o moc_predefs.h C:\Qt\5.10.1\android_armv7\mkspecs\features\data\dummy.cpp
    C:\Qt\5.10.1\android_armv7\bin\moc.exe -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_ANDROIDEXTRAS_LIB -DQT_CORE_LIB --include ./moc_predefs.h -IC:/Qt/5.10.1/android_armv7/mkspecs/android-g++ -IC:/Users/Philip/kodning/qtprojekt/CameraProjectJNIx -IC:/Qt/5.10.1/android_armv7/include -IC:/Qt/5.10.1/android_armv7/include/QtWidgets -IC:/Qt/5.10.1/android_armv7/include/QtGui -IC:/Qt/5.10.1/android_armv7/include/QtAndroidExtras -IC:/Qt/5.10.1/android_armv7/include/QtCore -I. -IC:/Users/Philip/AppData/Local/Android/Sdk/ndk-bundle/sysroot/usr/include/arm-linux-androideabi -IC:/Users/Philip/AppData/Local/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include -IC:/Users/Philip/AppData/Local/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/include -Ic:/users/philip/appdata/local/android/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/include -Ic:/users/philip/appdata/local/android/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/include-fixed -IC:/Users/Philip/AppData/Local/Android/Sdk/ndk-bundle/sysroot/usr/include ..\CameraProjectJNIx\mainwindow.h -o moc_mainwindow.cpp
    C:\Users\Philip\AppData\Local\Android\Sdk\ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/bin/arm-linux-androideabi-g++ -c -D__ANDROID_API__=16 --sysroot=C:\Users\Philip\AppData\Local\Android\Sdk\ndk-bundle/sysroot -isystem C:\Users\Philip\AppData\Local\Android\Sdk\ndk-bundle/sysroot/usr/include/arm-linux-androideabi -isystem C:\Users\Philip\AppData\Local\Android\Sdk\ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include -isystem C:\Users\Philip\AppData\Local\Android\Sdk\ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/include -fstack-protector-strong -DANDROID -march=armv7-a -mfloat-abi=softfp -mfpu=vfp -fno-builtin-memmove -g -g -marm -O0 -std=gnu++11 -Wall -W -D_REENTRANT -fPIC -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_ANDROIDEXTRAS_LIB -DQT_CORE_LIB -I..\CameraProjectJNIx -I. -IC:\Qt\5.10.1\android_armv7\include -IC:\Qt\5.10.1\android_armv7\include\QtWidgets -IC:\Qt\5.10.1\android_armv7\include\QtGui -IC:\Qt\5.10.1\android_armv7\include\QtAndroidExtras -IC:\Qt\5.10.1\android_armv7\include\QtCore -I. -I. -IC:\Qt\5.10.1\android_armv7\mkspecs\android-g++ -o moc_mainwindow.obj moc_mainwindow.cpp
    C:\Users\Philip\AppData\Local\Android\Sdk\ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/bin/arm-linux-androideabi-g++ --sysroot=C:\Users\Philip\AppData\Local\Android\Sdk\ndk-bundle/platforms/android-16/arch-arm/ -Wl,-soname,libCameraProjectJNIx.so -Wl,-rpath=C:/Qt/5.10.1/android_armv7/lib -Wl,--no-undefined -Wl,-z,noexecstack -shared -o libCameraProjectJNIx.so main.obj mainwindow.obj moc_mainwindow.obj   -LC:\Users\Philip\AppData\Local\Android\Sdk\ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a -Lc:/users/philip/appdata/local/android/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x -LC:/Qt/5.10.1/android_armv7/lib -lQt5Widgets -Lc:\utils\android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a -Lc:/utils/android-ndk-r10e/toolchains/arm-linux-androideabi-4.9/prebuilt/windows/bin/../lib/gcc/arm-linux-androideabi/4.9 -lQt5Gui -lQt5AndroidExtras -LC:\Qt\5.10.1\android_armv7/lib -lQt5Core -lGLESv2 -lgnustl_shared -lgcc -llog -lz -lm -ldl -lc
    10:50:43: The process "C:\Qt\Tools\mingw530_32\bin\mingw32-make.exe" exited normally.
    10:50:43: Removing directory C:\Users\Philip\kodning\qtprojekt\build-CameraProjectJNIx-Android_for_armeabi_v7a_GCC_4_9_Qt_5_10_1_for_Android_armv7-Debug\android-build/assets
    10:50:43: Removing directory C:\Users\Philip\kodning\qtprojekt\build-CameraProjectJNIx-Android_for_armeabi_v7a_GCC_4_9_Qt_5_10_1_for_Android_armv7-Debug\android-build/libs
    10:50:43: Starting: "C:\Qt\Tools\mingw530_32\bin\mingw32-make.exe" "INSTALL_ROOT=C:\Users\Philip\kodning\qtprojekt\build-CameraProjectJNIx-Android_for_armeabi_v7a_GCC_4_9_Qt_5_10_1_for_Android_armv7-Debug\android-build" install
    C:\Qt\5.10.1\android_armv7\bin\qmake.exe -install qinstall -exe libCameraProjectJNIx.so C:\Users\Philip\kodning\qtprojekt\build-CameraProjectJNIx-Android_for_armeabi_v7a_GCC_4_9_Qt_5_10_1_for_Android_armv7-Debug\android-build\libs\armeabi-v7a\libCameraProjectJNIx.so
    10:50:44: The process "C:\Qt\Tools\mingw530_32\bin\mingw32-make.exe" exited normally.
    10:50:44: Starting: "C:\Qt\5.10.1\android_armv7\bin\androiddeployqt.exe" --input C:/Users/Philip/kodning/qtprojekt/build-CameraProjectJNIx-Android_for_armeabi_v7a_GCC_4_9_Qt_5_10_1_for_Android_armv7-Debug/android-libCameraProjectJNIx.so-deployment-settings.json --output C:/Users/Philip/kodning/qtprojekt/build-CameraProjectJNIx-Android_for_armeabi_v7a_GCC_4_9_Qt_5_10_1_for_Android_armv7-Debug/android-build --deployment bundled --android-platform android-27 --jdk "C:/Program Files/Java/jdk1.8.0_162" --gradle
    Generating Android Package
      Input file: C:/Users/Philip/kodning/qtprojekt/build-CameraProjectJNIx-Android_for_armeabi_v7a_GCC_4_9_Qt_5_10_1_for_Android_armv7-Debug/android-libCameraProjectJNIx.so-deployment-settings.json
      Output directory: C:/Users/Philip/kodning/qtprojekt/build-CameraProjectJNIx-Android_for_armeabi_v7a_GCC_4_9_Qt_5_10_1_for_Android_armv7-Debug/android-build/
      Application binary: C:/Users/Philip/kodning/qtprojekt/build-CameraProjectJNIx-Android_for_armeabi_v7a_GCC_4_9_Qt_5_10_1_for_Android_armv7-Debug/libCameraProjectJNIx.so
      Android build platform: android-27
      Install to device: No
    The JavaCompile.setDependencyCacheDir() method has been deprecated and is scheduled to be removed in Gradle 4.0.
    The TaskInputs.source(Object) method has been deprecated and is scheduled to be removed in Gradle 4.0. Please use TaskInputs.file(Object).skipWhenEmpty() instead.
    :preBuild UP-TO-DATE
    :preDebugBuild UP-TO-DATE
    :checkDebugManifest
    :prepareDebugDependencies
    :compileDebugAidl UP-TO-DATE
    :compileDebugRenderscript
    :generateDebugBuildConfig UP-TO-DATE
    :generateDebugResValues UP-TO-DATE
    :generateDebugResources
    :mergeDebugResources UP-TO-DATE
    :processDebugManifest UP-TO-DATE
    :processDebugResources UP-TO-DATE
    :generateDebugSources
    :incrementalDebugJavaCompilationSafeguard UP-TO-DATE
    C:\Users\Philip\kodning\qtprojekt\build-CameraProjectJNIx-Android_for_armeabi_v7a_GCC_4_9_Qt_5_10_1_for_Android_armv7-Debug\android-build\src\com\vmi\StartCameraActivity.java:10: error: package android.support.v4.content does not exist
    import android.support.v4.content.FileProvider;  //How to "include" this in Android Qt?
                                     ^
    C:\Users\Philip\kodning\qtprojekt\build-CameraProjectJNIx-Android_for_armeabi_v7a_GCC_4_9_Qt_5_10_1_for_Android_armv7-Debug\android-build\src\com\vmi\StartCameraActivity.java:84: error: cannot find symbol
                    Uri photoURI = FileProvider.getUriForFile(this,
                                   ^
      symbol:   variable FileProvider
      location: class StartCameraActivity
    Note: Some input files use or override a deprecated API.
    Note: Recompile with -Xlint:deprecation for details.
    2 errors
    :compileDebugJavaWithJavac FAILED
    
    FAILURE: Build failed with an exception.
    
    * What went wrong:
    Execution failed for task ':compileDebugJavaWithJavac'.
    > Compilation failed; see the compiler error output for details.
    
    * Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
    
    BUILD FAILED
    
    Total time: 9.649 secs
    Building the android package failed!
      -- For more information, run this command with --verbose.
    10:50:57: The process "C:\Qt\5.10.1\android_armv7\bin\androiddeployqt.exe" exited with code 14.
    Error while building/deploying project CameraProjectJNIx (kit: Android for armeabi-v7a (GCC 4.9, Qt 5.10.1 for Android armv7))
    When executing step "Build Android APK"
    10:50:57: Elapsed time: 00:23.
    

    The most important part is this:

    C:\Users\Philip\kodning\qtprojekt\build-CameraProjectJNIx-Android_for_armeabi_v7a_GCC_4_9_Qt_5_10_1_for_Android_armv7-Debug\android-build\src\com\vmi\StartCameraActivity.java:10: error: package android.support.v4.content does not exist
    import android.support.v4.content.FileProvider;  //How to "include" this in Android Qt?
                                     ^
    C:\Users\Philip\kodning\qtprojekt\build-CameraProjectJNIx-Android_for_armeabi_v7a_GCC_4_9_Qt_5_10_1_for_Android_armv7-Debug\android-build\src\com\vmi\StartCameraActivity.java:84: error: cannot find symbol
                    Uri photoURI = FileProvider.getUriForFile(this,
                                   ^
      symbol:   variable FileProvider
      location: class StartCameraActivity
    Note: Some input files use or override a deprecated API.
    Note: Recompile with -Xlint:deprecation for details.
    2 errors
    :compileDebugJavaWithJavac FAILED
    
    FAILURE: Build failed with an exception.
    

    It seems like common files like android.content.Intent, android.os.Build, android.app.Activity and similar is available for the Qt (or Gradle or Android compiler or Java compiler, i dont know really). But "support"-stuff like android.support.v4.app.ActivityCompat and android.support.v4.content.FileProvider is not available for Qt. :(

    1. Why is not the Android support libraries available?

    2. How to make them available for the building process? I have seen a lot of funky stuff, like putting a lot of things in the AndroidManifest.xml or even the gradle file. :O . But if i could find a simpler less error prone way it would be nice. Maybe i can use the "Additional Libraries" in the Projects -> Build & Run -> ... -> Build ?

    (3. Where is the "Spoiler"-functionality in Qt Forums? I would like it for my long compile-text)

    Thanks for all answers, thoughts and comments.


  • Moderators

    @pga4711
    you need to add the support library to the build.gradle:

    ....
    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
    
        compile 'com.android.support:support-v4:25.3.1'
        ....
    }
    


  • @raven-worx
    Omg, now it compiles! :O

    Very good. Thank you.

    I wonder a bit about this anyway.

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile 'com.android.support:support-v4:25.3.1'
    }
    

    Where can i read about the structure of this?
    So the "compile"-statement(?) consist of three parts.

    1. com.android.support
    2. support-v4
    3. 25.3.1

    So the first thing is that we specefy the com.android.support library. And in that we would like to use the v4-library. Why is it a dash/hyphen? I have seen / as "package separator" in JNI calls but no dash, maybe a gradle-thing?. And what is this 25.3.1 ? Api 25 ? And what is 3.1?

    And why is the first and the second part not one nice "merged" fully qualified name like "android.support.v4" ?

    Two hours ago i tried stuff like tools:overrideLibrary as they suggest on Stackoverflow.

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
              package="com.vmi" ...
              xmlns:tools="http://schemas.android.com/tools">
    ...
      <uses-sdk android:targetSdkVersion="26" android:minSdkVersion="16"
                tools:overrideLibrary="android.support.v4"/>
    ...
    

    It did not work. If someone can explain why it does not work it will be fun.

    Thank you once again raven-worx.


  • Moderators

    @pga4711 said in Add Android Support libraries into the Qt project?:

    Where can i read about the structure of this?

    You could start here, but it's a common Android concept, so there are tons of material on the web about build.gradle files.

    And what is this 25.3.1 ? Api 25 ? And what is 3.1?

    no the version is not directly related to the API level.

    And why is the first and the second part not one nice "merged" fully qualified name like "android.support.v4" ?

    From the docs:

    Remote binary dependency
    compile 'com.example.android:app-magic:12.3'
    This is actually shorthand for the following:
    
    compile group: 'com.example.android', name: 'app-magic', version: '12.3'
    This declares a dependency on version 12.3 of the "app-magic" library, inside the "code.example.android" namespace group.
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.