You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Qt Android项目编译报错:package android.support.v4.app不存在

Fixing "package android.support.v4.app does not exist" in Qt Android + CMake Builds

Hey there, let's work through this frustrating error step by step—since you're using Qt 5.6+ with CMake (no Android Studio), we need to focus on how Qt handles Android dependencies and build configurations behind the scenes. Here are the key checks and fixes to try:

1. Verify Qt's Android Support Repository Path

Qt needs explicit access to your installed Android Support Repository to find the support-v4 libraries.

  • Open Qt Creator (even if you're building via command line, this helps confirm config) and go to Tools > Options > Devices > Android.
  • Double-check that the Android Support Repository path points to your actual installation (usually <SDK_ROOT>/extras/android/m2repository). If this path is missing or incorrect, Qt can't locate the support-v4 packages.

2. Correct Gradle Dependencies (and Make Qt Respect Them)

Qt generates its own Gradle files during build, so you need to add dependencies in a way that Qt won't overwrite:

  • Option 1: Use CMake to pass Gradle dependencies
    Add this line to your CMakeLists.txt file:
    set(QT_ANDROID_GRADLE_DEPENDENCIES "implementation 'com.android.support:support-v4:26.1.0'")
    
    Make sure the version (26.1.0) matches your target API level (26) — support library versions should align with your target SDK.
  • Option 2: Modify Qt's Gradle template
    If you have an android/gradle directory in your Qt project, edit the build.gradle file there to include:
    dependencies {
        implementation 'com.android.support:support-v4:26.1.0'
    }
    
    Also ensure your Gradle script includes the Google Maven repository (required for support libraries):
    repositories {
        google()
        mavenCentral()
    }
    

3. Ensure CMake Build Flags Are Correct

When running CMake via command line, double-check these critical parameters:

  • Specify the Qt Android toolchain:
    -DCMAKE_TOOLCHAIN_FILE=<QT_INSTALL_PATH>/5.6/android_armv7/lib/cmake/Qt5/Qt5AndroidToolchain.cmake
    
    Adjust android_armv7 to your target architecture (e.g., android_arm64_v8a).
  • Set SDK/NDK paths explicitly:
    -DANDROID_SDK_ROOT=<YOUR_SDK_PATH> -DANDROID_NDK=<YOUR_NDK_10d_PATH>
    
  • Confirm target SDK version matches your requirement:
    -DANDROID_TARGET_SDK_VERSION=26 -DANDROID_MIN_SDK_VERSION=16
    
    (Support-v4 26.x requires a minimum SDK of 16 or higher.)

4. Clean Build Caches

Qt and Gradle love to cache old configurations, which can cause dependency issues:

  • Delete your project's build directory entirely.
  • Remove Qt's temporary Android build files (usually in ~/.cache/QtProject or your project's .android subdirectory).
  • Re-run your CMake configure and build commands from scratch to generate fresh Gradle files.

5. Match Support Repository Version to Target API

Make sure you've installed the correct version of the Android Support Repository for API 26:

  • Open the Android SDK Manager and locate Android Support Repository.
  • Ensure you have a version that includes the 26.x support-v4 libraries (avoid AndroidX packages, since Qt 5.6+ doesn't support AndroidX natively). If your Support Repository is too new, it might only have AndroidX replacements—you may need to install an older version of the repository that still includes the legacy support libraries.

6. Consider Upgrading Qt (If Possible)

Qt 5.6 was an early release for Android API 26 support, and later versions (like 5.9 LTS) have more robust Android dependency handling. If your project allows, upgrading to a newer Qt version might resolve this issue without extra configuration headaches.

内容的提问来源于stack exchange,提问作者Max Pashkov

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 08:46:29