Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Troubles with QtAndroidTools
Forum Updated to NodeBB v4.3 + New Features

Troubles with QtAndroidTools

Scheduled Pinned Locked Moved Solved Mobile and Embedded
6 Posts 2 Posters 928 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dooham
    wrote on 12 Mar 2020, 11:31 last edited by
    #1

    Hello everyone,

    I want to implement the library QtAndroidTools of FalsinDoft because it has a lot of interesting features for Android.

    I followed the instructions of the documentation but I received the errors like:

    C:\Users\10alv\Documents\QtProgramas\PruebasAndroidTools\QtAndroidTools\QtAndroidTools.cpp:146: error: error: undefined reference to 'QAndroidAppPermissions::qmlInstance(QQmlEngine*, QJSEngine*)'
    
    C:\Qt\5.12.2\android_x86\include\QtQml\qqml.h:629: error: error: undefined reference to 'QAndroidGoogleAccount::staticMetaObject'
    
    C:\Qt\5.12.2\android_x86\include\QtCore\qmetatype.h:1476: error: error: undefined reference to 'QAndroidApkInfo::staticMetaObject'
    
    C:\Qt\5.12.2\android_x86\include\QtQml\qqmlprivate.h:103: error: error: undefined reference to 'QAndroidNotification::~QAndroidNotification()'
    
    C:\Qt\5.12.2\android_x86\include\QtCore\qmetatype.h:1832: error: error: undefined reference to 'QAndroidSharing::staticMetaObject'
    
    

    For my first test, I tried to make an app that ask you for some permissions.

    This is my .pro file:

    QT += quick
    
    CONFIG += c++11
    
    # The following define makes your compiler emit warnings if you use
    # any Qt feature that has been marked deprecated (the exact warnings
    # depend on your compiler). Refer to the documentation for the
    # deprecated API to know how to port your code away from it.
    DEFINES += QT_DEPRECATED_WARNINGS
    
    # You can also make your code fail to compile if it uses deprecated APIs.
    # In order to do so, uncomment the following line.
    # You can also select to disable deprecated APIs only up to a certain version of Qt.
    #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
    
    include(QtAndroidTools/QtAndroidTools.pri)
    
    SOURCES += \
            main.cpp
    
    RESOURCES += qml.qrc
    
    ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android
    
    DEFINES += \
        QTAT_APP_PERMISSIONS \
        QTAT_APK_EXPANSION_FILES \
        QTAT_APK_INFO \
        QTAT_SCREEN \
        QTAT_SYSTEM \
        QTAT_BATTERY_STATE \
        QTAT_SIGNAL_STRENGTH \
        QTAT_IMAGES \
        QTAT_NOTIFICATION \
        QTAT_ADMOB_BANNER \
        QTAT_ADMOB_INTERSTITIAL \
        QTAT_ADMOB_REWARDED_VIDEO \
        QTAT_PLAY_STORE \
        QTAT_GOOGLE_ACCOUNT \
        QTAT_GOOGLE_DRIVE \
        QTAT_SHARING
    
    # Additional import path used to resolve QML modules in Qt Creator's code model
    QML_IMPORT_PATH =
    
    # Additional import path used to resolve QML modules just for Qt Quick Designer
    QML_DESIGNER_IMPORT_PATH =
    
    # Default rules for deployment.
    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path = /opt/$${TARGET}/bin
    !isEmpty(target.path): INSTALLS += target
    
    

    This my main():

    #include <QGuiApplication>
    #include <QQmlApplicationEngine>
    #include <QtAndroidTools.h>
    
    int main(int argc, char *argv[])
    {
        QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    
        QGuiApplication app(argc, argv);
        QtAndroidTools::InitializeQmlTools();
    
        QQmlApplicationEngine engine;
        const QUrl url(QStringLiteral("qrc:/main.qml"));
        QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                         &app, [url](QObject *obj, const QUrl &objUrl) {
            if (!obj && url == objUrl)
                QCoreApplication::exit(-1);
        }, Qt::QueuedConnection);
        engine.load(url);
    
        return app.exec();
    }
    
    

    And finally my main.qml:

    import QtQuick 2.12
    import QtQuick.Controls 2.5
    import QtAndroidTools 1.0
    
    ApplicationWindow {
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
        color: "Red"
        readonly property var permissionsNameList: ["android.permission.WRITE_EXTERNAL_STORAGE","android.permission.READ_CALENDAR","android.permission.READ_PHONE_STATE","android.permission.READ_CONTACTS"]
    
    
        Button{
        x: 100
        y: 100
        width: 100
        height: 100
        onClicked: {
        QtAndroidAppPermissions.requestPermissions(permissionsNameList)
        }
        }
        Connections {
            target: QtAndroidAppPermissions
            onRequestPermissionsResults: {
                for(var i = 0; i < results.length; i++)
                {
                    if(results[i].granted === true)
                    {
                        setPermissionGranted(results[i].name, true);
                    }
                    else
                    {
                        if(QtAndroidAppPermissions.shouldShowRequestPermissionInfo(results[i].name) === true)
                        {
                            if(results[i].name === permissionsNameList[0])
                                requestPermissionWRITE_EXTERNAL_STORAGE.open();
                            else if(results[i].name === permissionsNameList[1])
                                requestPermissionREAD_CALENDAR.open();
                            else if(results[i].name === permissionsNameList[2])
                                requestPermissionREAD_PHONE_STATE.open();
                            else if(results[i].name === permissionsNameList[3])
                                requestPermissionREAD_CONTACTS.open();
                        }
                        else
                        {
                            setPermissionGranted(results[i].name, false);
                        }
                    }
                }
            }
        }
    }
    
    

    Does Anyones knows what I am doing wrong?

    Thanks for your answers.

    K 1 Reply Last reply 12 Mar 2020, 11:33
    0
    • D Dooham
      12 Mar 2020, 11:31

      Hello everyone,

      I want to implement the library QtAndroidTools of FalsinDoft because it has a lot of interesting features for Android.

      I followed the instructions of the documentation but I received the errors like:

      C:\Users\10alv\Documents\QtProgramas\PruebasAndroidTools\QtAndroidTools\QtAndroidTools.cpp:146: error: error: undefined reference to 'QAndroidAppPermissions::qmlInstance(QQmlEngine*, QJSEngine*)'
      
      C:\Qt\5.12.2\android_x86\include\QtQml\qqml.h:629: error: error: undefined reference to 'QAndroidGoogleAccount::staticMetaObject'
      
      C:\Qt\5.12.2\android_x86\include\QtCore\qmetatype.h:1476: error: error: undefined reference to 'QAndroidApkInfo::staticMetaObject'
      
      C:\Qt\5.12.2\android_x86\include\QtQml\qqmlprivate.h:103: error: error: undefined reference to 'QAndroidNotification::~QAndroidNotification()'
      
      C:\Qt\5.12.2\android_x86\include\QtCore\qmetatype.h:1832: error: error: undefined reference to 'QAndroidSharing::staticMetaObject'
      
      

      For my first test, I tried to make an app that ask you for some permissions.

      This is my .pro file:

      QT += quick
      
      CONFIG += c++11
      
      # The following define makes your compiler emit warnings if you use
      # any Qt feature that has been marked deprecated (the exact warnings
      # depend on your compiler). Refer to the documentation for the
      # deprecated API to know how to port your code away from it.
      DEFINES += QT_DEPRECATED_WARNINGS
      
      # You can also make your code fail to compile if it uses deprecated APIs.
      # In order to do so, uncomment the following line.
      # You can also select to disable deprecated APIs only up to a certain version of Qt.
      #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
      
      include(QtAndroidTools/QtAndroidTools.pri)
      
      SOURCES += \
              main.cpp
      
      RESOURCES += qml.qrc
      
      ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android
      
      DEFINES += \
          QTAT_APP_PERMISSIONS \
          QTAT_APK_EXPANSION_FILES \
          QTAT_APK_INFO \
          QTAT_SCREEN \
          QTAT_SYSTEM \
          QTAT_BATTERY_STATE \
          QTAT_SIGNAL_STRENGTH \
          QTAT_IMAGES \
          QTAT_NOTIFICATION \
          QTAT_ADMOB_BANNER \
          QTAT_ADMOB_INTERSTITIAL \
          QTAT_ADMOB_REWARDED_VIDEO \
          QTAT_PLAY_STORE \
          QTAT_GOOGLE_ACCOUNT \
          QTAT_GOOGLE_DRIVE \
          QTAT_SHARING
      
      # Additional import path used to resolve QML modules in Qt Creator's code model
      QML_IMPORT_PATH =
      
      # Additional import path used to resolve QML modules just for Qt Quick Designer
      QML_DESIGNER_IMPORT_PATH =
      
      # Default rules for deployment.
      qnx: target.path = /tmp/$${TARGET}/bin
      else: unix:!android: target.path = /opt/$${TARGET}/bin
      !isEmpty(target.path): INSTALLS += target
      
      

      This my main():

      #include <QGuiApplication>
      #include <QQmlApplicationEngine>
      #include <QtAndroidTools.h>
      
      int main(int argc, char *argv[])
      {
          QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
      
          QGuiApplication app(argc, argv);
          QtAndroidTools::InitializeQmlTools();
      
          QQmlApplicationEngine engine;
          const QUrl url(QStringLiteral("qrc:/main.qml"));
          QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                           &app, [url](QObject *obj, const QUrl &objUrl) {
              if (!obj && url == objUrl)
                  QCoreApplication::exit(-1);
          }, Qt::QueuedConnection);
          engine.load(url);
      
          return app.exec();
      }
      
      

      And finally my main.qml:

      import QtQuick 2.12
      import QtQuick.Controls 2.5
      import QtAndroidTools 1.0
      
      ApplicationWindow {
          visible: true
          width: 640
          height: 480
          title: qsTr("Hello World")
          color: "Red"
          readonly property var permissionsNameList: ["android.permission.WRITE_EXTERNAL_STORAGE","android.permission.READ_CALENDAR","android.permission.READ_PHONE_STATE","android.permission.READ_CONTACTS"]
      
      
          Button{
          x: 100
          y: 100
          width: 100
          height: 100
          onClicked: {
          QtAndroidAppPermissions.requestPermissions(permissionsNameList)
          }
          }
          Connections {
              target: QtAndroidAppPermissions
              onRequestPermissionsResults: {
                  for(var i = 0; i < results.length; i++)
                  {
                      if(results[i].granted === true)
                      {
                          setPermissionGranted(results[i].name, true);
                      }
                      else
                      {
                          if(QtAndroidAppPermissions.shouldShowRequestPermissionInfo(results[i].name) === true)
                          {
                              if(results[i].name === permissionsNameList[0])
                                  requestPermissionWRITE_EXTERNAL_STORAGE.open();
                              else if(results[i].name === permissionsNameList[1])
                                  requestPermissionREAD_CALENDAR.open();
                              else if(results[i].name === permissionsNameList[2])
                                  requestPermissionREAD_PHONE_STATE.open();
                              else if(results[i].name === permissionsNameList[3])
                                  requestPermissionREAD_CONTACTS.open();
                          }
                          else
                          {
                              setPermissionGranted(results[i].name, false);
                          }
                      }
                  }
              }
          }
      }
      
      

      Does Anyones knows what I am doing wrong?

      Thanks for your answers.

      K Offline
      K Offline
      KroMignon
      wrote on 12 Mar 2020, 11:33 last edited by
      #2

      @Dooham said in Troubles with QtAndroidTools:

      include(QtAndroidTools/QtAndroidTools.pri)

      I think you have to move include(QtAndroidTools/QtAndroidTools.pri) after the defines!

      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

      D 1 Reply Last reply 12 Mar 2020, 12:55
      1
      • K KroMignon
        12 Mar 2020, 11:33

        @Dooham said in Troubles with QtAndroidTools:

        include(QtAndroidTools/QtAndroidTools.pri)

        I think you have to move include(QtAndroidTools/QtAndroidTools.pri) after the defines!

        D Offline
        D Offline
        Dooham
        wrote on 12 Mar 2020, 12:55 last edited by
        #3

        @KroMignon Ok that worked but now I get other errors:

        symbol:   variable INITIATION_STARTED
          location: class AndroidGoogleDrive.FileUploadProgressListener
        C:\Users\10alv\Documents\QtProgramas\build-PruebasAndroidTools-Android_for_x86_Clang_Qt_5_12_2_for_Android_x86-Release\android-build\src\com\falsinsoft\qtandroidtools\AndroidGoogleDrive.java:380: error: cannot find symbol
                        case INITIATION_COMPLETE:
                             ^
          symbol:   variable INITIATION_COMPLETE
          location: class AndroidGoogleDrive.FileUploadProgressListener
        C:\Users\10alv\Documents\QtProgramas\build-PruebasAndroidTools-Android_for_x86_Clang_Qt_5_12_2_for_Android_x86-Release\android-build\src\com\falsinsoft\qtandroidtools\AndroidGoogleDrive.java:383: error: cannot find symbol
                        case MEDIA_IN_PROGRESS:
        
        Note: Some input files use or override a deprecated API.
        Note: Recompile with -Xlint:deprecation for details.
        85 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. Run with --scan to get full insights.
        
        * Get more help at https://help.gradle.org
        
        BUILD FAILED in 30s
        
        K 1 Reply Last reply 12 Mar 2020, 13:22
        0
        • D Dooham
          12 Mar 2020, 12:55

          @KroMignon Ok that worked but now I get other errors:

          symbol:   variable INITIATION_STARTED
            location: class AndroidGoogleDrive.FileUploadProgressListener
          C:\Users\10alv\Documents\QtProgramas\build-PruebasAndroidTools-Android_for_x86_Clang_Qt_5_12_2_for_Android_x86-Release\android-build\src\com\falsinsoft\qtandroidtools\AndroidGoogleDrive.java:380: error: cannot find symbol
                          case INITIATION_COMPLETE:
                               ^
            symbol:   variable INITIATION_COMPLETE
            location: class AndroidGoogleDrive.FileUploadProgressListener
          C:\Users\10alv\Documents\QtProgramas\build-PruebasAndroidTools-Android_for_x86_Clang_Qt_5_12_2_for_Android_x86-Release\android-build\src\com\falsinsoft\qtandroidtools\AndroidGoogleDrive.java:383: error: cannot find symbol
                          case MEDIA_IN_PROGRESS:
          
          Note: Some input files use or override a deprecated API.
          Note: Recompile with -Xlint:deprecation for details.
          85 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. Run with --scan to get full insights.
          
          * Get more help at https://help.gradle.org
          
          BUILD FAILED in 30s
          
          K Offline
          K Offline
          KroMignon
          wrote on 12 Mar 2020, 13:22 last edited by
          #4

          @Dooham It look like there is an error in java class, the best is to contact the author. Maybe an Android API Level issue?
          I don't know

          It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

          1 Reply Last reply
          1
          • D Offline
            D Offline
            Dooham
            wrote on 12 Mar 2020, 14:08 last edited by
            #5

            After doing some changes in the gradle file, I solved some errors but I get another one:

            * What went wrong:
            Execution failed for task ':transformResourcesWithMergeJavaResForDebug'.
            > More than one file was found with OS independent path 'META-INF/DEPENDENCIES'
            
            * Try:
            Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
            
            * Get more help at https://help.gradle.org
            
            BUILD FAILED in 22s
            27 actionable tasks: 1 executed, 26 up-to-date
            

            Does anyones know the solution?

            D 1 Reply Last reply 12 Mar 2020, 15:12
            0
            • D Dooham
              12 Mar 2020, 14:08

              After doing some changes in the gradle file, I solved some errors but I get another one:

              * What went wrong:
              Execution failed for task ':transformResourcesWithMergeJavaResForDebug'.
              > More than one file was found with OS independent path 'META-INF/DEPENDENCIES'
              
              * Try:
              Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
              
              * Get more help at https://help.gradle.org
              
              BUILD FAILED in 22s
              27 actionable tasks: 1 executed, 26 up-to-date
              

              Does anyones know the solution?

              D Offline
              D Offline
              Dooham
              wrote on 12 Mar 2020, 15:12 last edited by
              #6

              @Dooham Ok I found the trouble. You have to add the following lines to the build.graddle:

               aaptOptions {
                      noCompress 'rcc'
                  }
              	
              	packagingOptions {
                      exclude 'META-INF/DEPENDENCIES'
                      exclude 'META-INF/LICENSE'
                      exclude 'META-INF/LICENSE.txt'
                      exclude 'META-INF/license.txt'
                      exclude 'META-INF/NOTICE'
                      exclude 'META-INF/NOTICE.txt'
                      exclude 'META-INF/notice.txt'
                      exclude 'META-INF/ASL2.0'
                  }
              

              Almost every trouble that I had was related with this file, I let you the final build.gradle that I use and it seems works:

              buildscript {
                  repositories {
                      google()
                      jcenter()
                  }
              
                  dependencies {
                      classpath 'com.android.tools.build:gradle:3.2.0'
              
                  }
              }
              
              repositories {
                  google()
                  jcenter()
              }
              
              apply plugin: 'com.android.application'
              
              dependencies {
                  implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
                  implementation 'com.android.support:support-v4:26.+'
                      implementation 'com.google.android.gms:play-services-ads:16.+'
                      implementation 'com.google.android.gms:play-services-auth:16.+'
                      implementation 'com.google.http-client:google-http-client-gson:1.26.0'
                      implementation('com.google.api-client:google-api-client-android:1.26.0') {
                          exclude group: 'org.apache.httpcomponents'
                      }
                      implementation ('com.google.apis:google-api-services-drive:v3-rev173-1.25.0') {
                          exclude group: 'org.apache.httpcomponents'
                      }
              }
              
              android {
                  /*******************************************************
                   * The following variables:
                   * - androidBuildToolsVersion,
                   * - androidCompileSdkVersion
                   * - qt5AndroidDir - holds the path to qt android files
                   *                   needed to build any Qt application
                   *                   on Android.
                   *
                   * are defined in gradle.properties file. This file is
                   * updated by QtCreator and androiddeployqt tools.
                   * Changing them manually might break the compilation!
                   *******************************************************/
              
                  compileSdkVersion androidCompileSdkVersion.toInteger()
              
                  buildToolsVersion androidBuildToolsVersion
              
                  sourceSets {
                      main {
                          manifest.srcFile 'AndroidManifest.xml'
                          java.srcDirs = [qt5AndroidDir + '/src', 'src', 'java']
                          aidl.srcDirs = [qt5AndroidDir + '/src', 'src', 'aidl']
                          res.srcDirs = [qt5AndroidDir + '/res', 'res']
                          resources.srcDirs = ['src']
                          renderscript.srcDirs = ['src']
                          assets.srcDirs = ['assets']
                          jniLibs.srcDirs = ['libs']
                     }
                  }
              
                  lintOptions {
                      abortOnError false
                  }
              
              aaptOptions {
                     noCompress 'rcc'
                 }
              
                     packagingOptions {
                     exclude 'META-INF/DEPENDENCIES'
                     exclude 'META-INF/LICENSE'
                     exclude 'META-INF/LICENSE.txt'
                     exclude 'META-INF/license.txt'
                     exclude 'META-INF/NOTICE'
                     exclude 'META-INF/NOTICE.txt'
                     exclude 'META-INF/notice.txt'
                     exclude 'META-INF/ASL2.0'
                 }
              
                }
              
              
              
              1 Reply Last reply
              0

              1/6

              12 Mar 2020, 11:31

              • Login

              • Login or register to search.
              1 out of 6
              • First post
                1/6
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved