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. Can't import androidx. Error: 'Package androidx.core.app does not exist.'

Can't import androidx. Error: 'Package androidx.core.app does not exist.'

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
androidjavapackageqt 6.8.2
16 Posts 2 Posters 619 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.
  • J Offline
    J Offline
    J.Hilk
    Moderators
    wrote on 26 Mar 2025, 08:50 last edited by
    #5

    I'm actively using:

    import androidx.core.content.FileProvider;
    import androidx.core.app.ShareCompat;

    the the files are there for me :D


    Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


    Q: What's that?
    A: It's blue light.
    Q: What does it do?
    A: It turns blue.

    1 Reply Last reply
    0
    • V Offline
      V Offline
      VicDm
      wrote on 26 Mar 2025, 09:19 last edited by
      #6

      @J-Hilk Oh that's interesting, may I know If you use Qt 6.8.2 or not? As that's what I am using. It would also be helpful if you could compare the below gradle.properties to yours so that I can try changing the values. android.useAndroidX=true
      android.enableJetifier=true
      androidBuildToolsVersion=35.0.0
      androidCompileSdkVersion=android-35
      androidNdkVersion=26.1.10909125
      buildDir=build
      qt5AndroidDir=/Users/abcd/Qt/6.8.2/android_arm64_v8a/./src/android/java
      qtAndroidDir=/Users/abcd/Qt/6.8.2/android_arm64_v8a/./src/android/java
      qtGradlePluginType=com.android.application
      qtTargetAbiList=arm64-v8a
      qtMinSdkVersion=28
      qtTargetSdkVersion=34

      J 1 Reply Last reply 26 Mar 2025, 09:42
      0
      • V VicDm
        26 Mar 2025, 09:19

        @J-Hilk Oh that's interesting, may I know If you use Qt 6.8.2 or not? As that's what I am using. It would also be helpful if you could compare the below gradle.properties to yours so that I can try changing the values. android.useAndroidX=true
        android.enableJetifier=true
        androidBuildToolsVersion=35.0.0
        androidCompileSdkVersion=android-35
        androidNdkVersion=26.1.10909125
        buildDir=build
        qt5AndroidDir=/Users/abcd/Qt/6.8.2/android_arm64_v8a/./src/android/java
        qtAndroidDir=/Users/abcd/Qt/6.8.2/android_arm64_v8a/./src/android/java
        qtGradlePluginType=com.android.application
        qtTargetAbiList=arm64-v8a
        qtMinSdkVersion=28
        qtTargetSdkVersion=34

        J Offline
        J Offline
        J.Hilk
        Moderators
        wrote on 26 Mar 2025, 09:42 last edited by
        #7

        @VicDm
        there's nothing special to it, here it is in full. I did remove commented out stuff for readability:

        buildscript {
            repositories {
                google()
                mavenCentral()
            }
        
            dependencies {
                classpath 'com.android.tools.build:gradle:8.6.0'
            }
        }
        
        repositories {
            google()
            mavenCentral()
        }
        
        apply plugin: qtGradlePluginType
        
        dependencies {
            implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
            implementation 'androidx.core:core:1.13.1'
        }
        
        android {
            /*******************************************************
             * The following variables:
             * - androidBuildToolsVersion,
             * - androidCompileSdkVersion
             * - qtAndroidDir - holds the path to qt android files
             *                   needed to build any Qt application
             *                   on Android.
             * - qtGradlePluginType - whether to build an app or a library
             *
             * are defined in gradle.properties file. This file is
             * updated by QtCreator and androiddeployqt tools.
             * Changing them manually might break the compilation!
             *******************************************************/
        
            namespace androidPackageName
            compileSdkVersion androidCompileSdkVersion
            buildToolsVersion androidBuildToolsVersion
            ndkVersion androidNdkVersion
        
            // Extract native libraries from the APK
            packagingOptions.jniLibs.useLegacyPackaging true
        
            sourceSets {
                main {
                    manifest.srcFile 'AndroidManifest.xml'
                    java.srcDirs = [qtAndroidDir + '/src', 'src', 'java']
                    aidl.srcDirs = [qtAndroidDir + '/src', 'src', 'aidl']
                    res.srcDirs = [qtAndroidDir + '/res', 'res']
                    resources.srcDirs = ['resources']
                    renderscript.srcDirs = ['src']
                    assets.srcDirs = ['assets']
                    jniLibs.srcDirs = ['libs']
               }
            }
        
            tasks.withType(JavaCompile) {
                options.incremental = true
            }
        
            compileOptions {
                sourceCompatibility JavaVersion.VERSION_1_8
                targetCompatibility JavaVersion.VERSION_1_8
            }
        
            lintOptions {
                abortOnError false
            }
        
            // Do not compress Qt binary resources file
            aaptOptions {
                noCompress 'rcc'
            }
        
            defaultConfig {
                resConfig "en"
                minSdkVersion qtMinSdkVersion
                targetSdkVersion qtTargetSdkVersion
                ndk.abiFilters = qtTargetAbiList.split(",")
            }
        }
        

        I spend a lot of time the last couple of weeks trying to compile with Qt6. The the .gradle file might be a bit messy.


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        V 1 Reply Last reply 26 Mar 2025, 09:53
        0
        • J J.Hilk
          26 Mar 2025, 09:42

          @VicDm
          there's nothing special to it, here it is in full. I did remove commented out stuff for readability:

          buildscript {
              repositories {
                  google()
                  mavenCentral()
              }
          
              dependencies {
                  classpath 'com.android.tools.build:gradle:8.6.0'
              }
          }
          
          repositories {
              google()
              mavenCentral()
          }
          
          apply plugin: qtGradlePluginType
          
          dependencies {
              implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
              implementation 'androidx.core:core:1.13.1'
          }
          
          android {
              /*******************************************************
               * The following variables:
               * - androidBuildToolsVersion,
               * - androidCompileSdkVersion
               * - qtAndroidDir - holds the path to qt android files
               *                   needed to build any Qt application
               *                   on Android.
               * - qtGradlePluginType - whether to build an app or a library
               *
               * are defined in gradle.properties file. This file is
               * updated by QtCreator and androiddeployqt tools.
               * Changing them manually might break the compilation!
               *******************************************************/
          
              namespace androidPackageName
              compileSdkVersion androidCompileSdkVersion
              buildToolsVersion androidBuildToolsVersion
              ndkVersion androidNdkVersion
          
              // Extract native libraries from the APK
              packagingOptions.jniLibs.useLegacyPackaging true
          
              sourceSets {
                  main {
                      manifest.srcFile 'AndroidManifest.xml'
                      java.srcDirs = [qtAndroidDir + '/src', 'src', 'java']
                      aidl.srcDirs = [qtAndroidDir + '/src', 'src', 'aidl']
                      res.srcDirs = [qtAndroidDir + '/res', 'res']
                      resources.srcDirs = ['resources']
                      renderscript.srcDirs = ['src']
                      assets.srcDirs = ['assets']
                      jniLibs.srcDirs = ['libs']
                 }
              }
          
              tasks.withType(JavaCompile) {
                  options.incremental = true
              }
          
              compileOptions {
                  sourceCompatibility JavaVersion.VERSION_1_8
                  targetCompatibility JavaVersion.VERSION_1_8
              }
          
              lintOptions {
                  abortOnError false
              }
          
              // Do not compress Qt binary resources file
              aaptOptions {
                  noCompress 'rcc'
              }
          
              defaultConfig {
                  resConfig "en"
                  minSdkVersion qtMinSdkVersion
                  targetSdkVersion qtTargetSdkVersion
                  ndk.abiFilters = qtTargetAbiList.split(",")
              }
          }
          

          I spend a lot of time the last couple of weeks trying to compile with Qt6. The the .gradle file might be a bit messy.

          V Offline
          V Offline
          VicDm
          wrote on 26 Mar 2025, 09:53 last edited by
          #8

          @J-Hilk So you do use qt 6.8.2 ? and your values in gradle.properties are similar to mine? as you have shared your build.gradle file with me and not gradle.properties.

          1 Reply Last reply
          0
          • J Offline
            J Offline
            J.Hilk
            Moderators
            wrote on 26 Mar 2025, 10:14 last edited by
            #9

            6.8.1

            # Project-wide Gradle settings.
            # For more details on how to configure your build environment visit
            # http://www.gradle.org/docs/current/userguide/build_environment.html
            # Specifies the JVM arguments used for the daemon process.
            # The setting is particularly useful for tweaking memory settings.
            org.gradle.jvmargs=-Xmx2500m -XX:MaxMetaspaceSize=768m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
            
            # Enable building projects in parallel
            org.gradle.parallel=true
            
            # Gradle caching allows reusing the build artifacts from a previous
            # build with the same inputs. However, over time, the cache size will
            # grow. Uncomment the following line to enable it.
            #org.gradle.caching=true
            #org.gradle.configuration-cache=true
            
            # Allow AndroidX usage
            android.useAndroidX=true
            
            

            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            V 1 Reply Last reply 26 Mar 2025, 14:33
            0
            • J J.Hilk
              26 Mar 2025, 10:14

              6.8.1

              # Project-wide Gradle settings.
              # For more details on how to configure your build environment visit
              # http://www.gradle.org/docs/current/userguide/build_environment.html
              # Specifies the JVM arguments used for the daemon process.
              # The setting is particularly useful for tweaking memory settings.
              org.gradle.jvmargs=-Xmx2500m -XX:MaxMetaspaceSize=768m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
              
              # Enable building projects in parallel
              org.gradle.parallel=true
              
              # Gradle caching allows reusing the build artifacts from a previous
              # build with the same inputs. However, over time, the cache size will
              # grow. Uncomment the following line to enable it.
              #org.gradle.caching=true
              #org.gradle.configuration-cache=true
              
              # Allow AndroidX usage
              android.useAndroidX=true
              
              
              V Offline
              V Offline
              VicDm
              wrote on 26 Mar 2025, 14:33 last edited by
              #10

              @J-Hilk I checked my dependencies in my project and it shows androidx.core. It's actually really difficult to pin point the issue. I tried going through my files and documentation online. I'm not sure, do I need to mention explicitly somewhere about the usage of androidx or do I need some additional statements in my AndroidManifest ?

              1 Reply Last reply
              0
              • J Offline
                J Offline
                J.Hilk
                Moderators
                wrote on 26 Mar 2025, 14:49 last edited by
                #11

                In my case I actually have to reference it in the AndroidManifest

                <provider android:name="androidx.core.content.FileProvider" android:authorities="redacted" android:exported="false" android:grantUriPermissions="true">
                            <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/filepaths"/>
                        </provider>
                

                But thats so that the file provider from the androidx library actually gets the needed permissions to function correctly.

                Shouldn't matter for compilation


                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                V 1 Reply Last reply 26 Mar 2025, 15:15
                0
                • J J.Hilk
                  26 Mar 2025, 14:49

                  In my case I actually have to reference it in the AndroidManifest

                  <provider android:name="androidx.core.content.FileProvider" android:authorities="redacted" android:exported="false" android:grantUriPermissions="true">
                              <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/filepaths"/>
                          </provider>
                  

                  But thats so that the file provider from the androidx library actually gets the needed permissions to function correctly.

                  Shouldn't matter for compilation

                  V Offline
                  V Offline
                  VicDm
                  wrote on 26 Mar 2025, 15:15 last edited by
                  #12

                  @J-Hilk This is what I have in my AndroidManifest.

                  <provider android:name="androidx.core.content.FileProvider" android:authorities="${applicationId}.qtprovider" android:exported="false" android:grantUriPermissions="true">
                             <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/qtprovider_paths"/>
                  </provider>
                  

                  this is newly generated in every build.

                  qtprovider_paths.xml

                  <?xml version="1.0" encoding="utf-8"?>
                  <paths xmlns:android="http://schemas.android.com/apk/res/android">
                      <files-path name="files_path" path="/"/>
                  </paths>
                  

                  Is there something missing here?

                  1 Reply Last reply
                  0
                  • J Offline
                    J Offline
                    J.Hilk
                    Moderators
                    wrote on 26 Mar 2025, 15:29 last edited by J.Hilk
                    #13

                    ok, maybe I should have started with this.

                    Do you provide QtCreator & qmake/cmake - I presume you use QtC - with your own android & gradle settings/files ? And if you think you do, how exactly ?


                    Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                    Q: What's that?
                    A: It's blue light.
                    Q: What does it do?
                    A: It turns blue.

                    V 1 Reply Last reply 26 Mar 2025, 15:47
                    0
                    • J J.Hilk
                      26 Mar 2025, 15:29

                      ok, maybe I should have started with this.

                      Do you provide QtCreator & qmake/cmake - I presume you use QtC - with your own android & gradle settings/files ? And if you think you do, how exactly ?

                      V Offline
                      V Offline
                      VicDm
                      wrote on 26 Mar 2025, 15:47 last edited by
                      #14

                      @J-Hilk Yes I use CMake and the android & gradle settings/files are generated by QT on build.

                      /Users/abcd/Workspace/App/build/Android_Qt_6_8_2_Clang_arm64_v8a-Debug/android-build-LiftboyApp/build.gradle
                      

                      android_bundle.cmake

                      if (ANDROID)
                          set(LFSP_ANDROID_DIR ${CMAKE_CURRENT_SOURCE_DIR}/android)
                          option(QT_ANDROID_BUILD_ALL_ABIS ON)
                      
                          set_target_properties(${LFSP_APP_BUNDLE} PROPERTIES
                              QT_ANDROID_PACKAGE_SOURCE_DIR ${LFSP_ANDROID_DIR}
                              RESOURCE  ${LFSP_ANDROID_DIR}/AndroidManifest.xml
                              QT_ANDROID_TARGET_SDK_VERSION ${LFSP_ANDROID_TARGET_SDK}
                              QT_ANDROID_VERSION_NAME ${CMAKE_PROJECT_VERSION}
                              QT_ANDROID_VERSION_CODE ${LFSP_ANDROID_VERSION_CODE}
                              QT_ANDROID_BUILD_ALL_ABIS ${LFSP_ANDROID_ALL_ABIS})
                          message("android: ${LFSP_APP_BUNDLE} v${CMAKE_PROJECT_VERSION}, code ${LFSP_ANDROID_VERSION_CODE}, target-sdk: ${LFSP_ANDROID_TARGET_SDK}, all abis: ${LFSP_ANDROID_ALL_ABIS}")
                      endif()
                      

                      short snippet of CMakeLists.txt

                      set(LFSP_BASE ${CMAKE_CURRENT_LIST_DIR}/..)
                      set(LFSP_ANDROID_VERSION_CODE 87)
                      set(LFSP_ANDROID_TARGET_SDK 34)
                      set(LFSP_ANDROID_JAVA_VERSION 17)
                      if(CMAKE_BUILD_TYPE STRLESS_EQUAL "Debug")
                          set(LFSP_ANDROID_ALL_ABIS OFF)
                      else()
                          set(LFSP_ANDROID_ALL_ABIS ON)
                      endif()
                      set(LFSP_APP_BUNDLE App CACHE STRING "" FORCE)
                      include(android_bundle)
                      
                      1 Reply Last reply
                      0
                      • J Offline
                        J Offline
                        J.Hilk
                        Moderators
                        wrote on 27 Mar 2025, 06:42 last edited by
                        #15

                        ok, my cmake experience is nearly non existent, but it seems to be fine. Mmh.

                        I have no idea why it doesn't work for you.


                        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                        Q: What's that?
                        A: It's blue light.
                        Q: What does it do?
                        A: It turns blue.

                        1 Reply Last reply
                        0
                        • V Offline
                          V Offline
                          VicDm
                          wrote on 27 Mar 2025, 07:32 last edited by VicDm
                          #16

                          @J-Hilk It all looks fine to me as well, this is why it's even more difficult to find the issue. Oh well, guess I have to spend more time on this than I had planned to. Thanks for all your help tho, I highly appreciate it! :)

                          1 Reply Last reply
                          1

                          14/16

                          26 Mar 2025, 15:47

                          • Login

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