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 594 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.
  • V Offline
    V Offline
    VicDm
    wrote on 25 Mar 2025, 15:35 last edited by
    #1

    I would like to integrate Android Auto compatibility in my mobile app. For this I would like to use the androidx library. However when I try to import anything from androidx I get an error.

    NotificationRegistry.java:17: error: package androidx.core.app does not exist
    :-1: error: ninja: build stopped: subcommand failed.
    

    For example currently I am trying to import "import androidx.core.app.RemoteInput;" in my java class. I found a topic on this forum dated back in 2020 where it said to enableJetifier I did this, however that did not help me.

    Below is my build.gradle

    buildscript {
        repositories {
            google()
            mavenCentral()
        }
    
        dependencies {
            //noinspection AndroidGradlePluginVersion
            classpath 'com.android.tools.build:gradle:8.9.0'
        }
    }
    
    allprojects {
        repositories {
            google()
            mavenCentral()
        }
    }
    
    repositories {
        google()
        mavenCentral()
    }
    
    apply plugin: qtGradlePluginType
    
    dependencies {
        implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
        //noinspection GradleDependency
        implementation 'androidx.core:core:1.15.0'
    }
    
    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_17
            targetCompatibility JavaVersion.VERSION_17
        }
    
        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 then tried to manually set the minimum sdk & target sdk version, etc but this gets overriden with a new value set by Qt Creator during every build. Below is a short snippet of my gradle.properties file. the code commented out is what I manually add but then is overridden by Qt and as you see I have enabled jetifier and the use of AndroidX.

    gradle.properties

    android.useAndroidX=true
    android.enableJetifier=true
    #androidNdkVersion=29.0.13113456
    androidNdkVersion=26.1.10909125
    #qtMinSdkVersion=29
    qtTargetAbiList=arm64-v8a
    #qtTargetSdkVersion=35
    qtMinSdkVersion=28
    qtTargetSdkVersion=34
    

    When I open my project in android studio using Debug APK I see that androidx exists however I can't import it in any of my java classes.

    I am new to QT and would really appreciate some help. If you need any other information please do let me know. Thanks in advance !

    1 Reply Last reply
    0
    • V VicDm referenced this topic on 26 Mar 2025, 07:45
    • J Online
      J Online
      J.Hilk
      Moderators
      wrote on 26 Mar 2025, 07:56 last edited by
      #2

      1.15.0 is the latest stable version, its possible its not part of your repo

      I'm using implementation 'androidx.core:core:1.13.1' and classpath 'com.android.tools.build:gradle:8.6.0' and I'm using this repo, specified in the cradle-wrapper.properties:
      distributionUrl=https://services.gradle.org/distributions/gradle-8.10-bin.zip

      I do not use Android auto, so I don't know if these settings would help 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.

      V 1 Reply Last reply 26 Mar 2025, 08:46
      0
      • V Offline
        V Offline
        VicDm
        wrote on 26 Mar 2025, 08:15 last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • J J.Hilk
          26 Mar 2025, 07:56

          1.15.0 is the latest stable version, its possible its not part of your repo

          I'm using implementation 'androidx.core:core:1.13.1' and classpath 'com.android.tools.build:gradle:8.6.0' and I'm using this repo, specified in the cradle-wrapper.properties:
          distributionUrl=https://services.gradle.org/distributions/gradle-8.10-bin.zip

          I do not use Android auto, so I don't know if these settings would help you ?

          V Offline
          V Offline
          VicDm
          wrote on 26 Mar 2025, 08:46 last edited by
          #4

          @J-Hilk Yes, that's what I initially had. These settings weren't working for me this is why I updated the versions thinking that maybe I need a latest version. Are you able to import " import androidx.core.app.NotificationCompat; " into any of your java classes? This is just one of the imports but can be a good example to test.

          1 Reply Last reply
          0
          • J Online
            J Online
            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 Online
                J Online
                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 Online
                    J Online
                    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 Online
                        J Online
                        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 Online
                            J Online
                            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 Online
                                J Online
                                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

                                  2/16

                                  26 Mar 2025, 07:56

                                  topic:navigator.unread, 14
                                  • Login

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