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

Qt 6.7.0中AndroidManifest.xml修改后构建目录未同步求助

Qt 6.7.0 Android项目自定义AndroidManifest.xml未同步构建目录的解决方法

问题描述

使用Qt 6.7.0开发Android应用时,通过项目构建菜单的「创建模板」生成AndroidManifest.xml并修改后,已将该文件所在目录注册到CMake项目中,但构建目录内的AndroidManifest.xml始终未同步修改内容,而是以默认参数重新生成。自定义Manifest内容如下:

<?xml version="1.0"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.qtproject.example.Shopot" android:installLocation="auto" android:versionCode="1" android:versionName="1.0">
    <!-- %%INSERT_PERMISSIONS -->
    <!-- %%INSERT_FEATURES -->
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.READ_CONTACTS"/>
    <uses-permission android:name="android.permission.RECORD_AUDIO"/>
    <uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
    <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:smallScreens="true"/>
    <application android:name="org.qtproject.qt.android.bindings.QtApplication" android:hardwareAccelerated="true" android:label="Shopot" android:requestLegacyExternalStorage="true" android:allowBackup="true" android:fullBackupOnly="false" android:icon="@mipmap/ic_launcher">
        <activity android:name="org.qtproject.qt.android.bindings.QtActivity" android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation|mcc|mnc|density" android:label="Shopot" android:launchMode="singleTop" android:screenOrientation="unspecified" android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
            <meta-data android:name="android.app.extract_android_style" android:value="minimal"/>
        </activity>

        <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>
    </application>
</manifest>

该问题关联已知Qt Creator Bug,以下是可行的解决方法:

解决方法

1. 修正CMake配置,明确指定Manifest文件

仅注册目录无效,必须在CMakeLists.txt中显式指定自定义Manifest的路径:

  • 在qt_add_executable之前添加:
    set(ANDROID_MANIFEST_FILE ${CMAKE_SOURCE_DIR}/android/AndroidManifest.xml)
    
    (替换路径为你的Manifest实际存放路径)
  • 或者通过set_target_properties为目标指定:
    set_target_properties(Shopot PROPERTIES
        ANDROID_MANIFEST_FILE ${CMAKE_SOURCE_DIR}/android/AndroidManifest.xml
    )
    

2. 清理构建缓存并重新构建

Qt Creator可能缓存旧的Manifest文件,执行以下操作:

  • 手动删除项目的build目录
  • 或在Qt Creator中依次选择「构建」→「清理项目」,再执行「重新构建」

3. 针对该Bug的临时绕过方案

如果上述方法无效,可通过以下方式强制同步:

  • 手动复制自定义AndroidManifest.xml到构建目录的android-build子目录下,覆盖自动生成的文件后再构建
  • 或在CMake中添加自定义命令,构建后自动复制Manifest:
    add_custom_command(TARGET Shopot POST_BUILD
        COMMAND ${CMAKE_COMMAND} -E copy_if_different
            ${CMAKE_SOURCE_DIR}/android/AndroidManifest.xml
            ${CMAKE_BINARY_DIR}/android-build/AndroidManifest.xml
    )
    

4. 移除Manifest模板注释(可选)

如果不需要Qt自动插入权限和特性,删除Manifest中的<!-- %%INSERT_PERMISSIONS -->和<!-- %%INSERT_FEATURES -->注释,避免Qt自动生成内容覆盖自定义设置。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.25 14:47:12