AndroidManifest.xml中application标签属性详解 —— 新手指南

一、基础配置类属性

属性 用途 最低API 是否过时 示例 兼容性说明
android:name 自定义 Application 子类(全局入口) 1 android:name=".MyApplication" 必须继承自 android.app.Application
android:icon 应用默认图标(Launcher/Settings 显示) 1 android:icon="@mipmap/ic_launcher" 需提供自适应图标 (mipmap-anydpi-v26/ic_launcher.xml)
android:label 应用显示名称 1 android:label="@string/app_name" 多语言需配置 strings.xml 的翻译资源
android:theme 全局主题样式 1 android:theme="@style/AppTheme" 可被 Activity 主题覆盖
android:description 应用描述(辅助功能/TTS) 1 android:description="@string/app_description" 需配置 android:accessibilityDescription 以增强无障碍支持

二、安全与权限类属性

属性 用途 最低API 是否过时 示例 兼容性说明
android:permission 应用级全局权限 1 android:permission="android.permission.INTERNET" 被组件级权限声明覆盖
android:allowBackup 是否允许自动备份到云端 8 android:allowBackup="false" API 23+ 需配合 android:fullBackupContent 使用
android:networkSecurityConfig 自定义网络安全策略(HTTPS 强制/证书固定) 24 android:networkSecurityConfig="@xml/network_security" API 24+ 必须使用,取代 android:usesCleartextTraffic
android:requestLegacyExternalStorage 禁用分区存储(Scoped Storage) 29 ✅ (API 30+) android:requestLegacyExternalStorage="true" ​仅对 API 29~30 有效​​,API 31+ 强制分区存储
android:usesNonSdkApi 声明使用非 SDK 接口(需 Google Play 白名单) 28 android:usesNonSdkApi="true" 需使用 Veridex 检测
android:crossProfile 跨用户配置文件访问权限 34 android:crossProfile="true" 需声明 android.permission.INTERACT_ACROSS_USERS

三、性能与优化类属性

属性 用途 最低API 是否过时 示例 兼容性说明
android:hardwareAccelerated 全局启用硬件加速 11 android:hardwareAccelerated="true" 默认启用,可在 Activity 级覆盖
android:largeHeap 申请更大堆内存(谨慎使用) 11 android:largeHeap="true" 可能导致系统性能下降
android:persistent 声明为常驻进程(系统级应用专用) 1 android:persistent="true" android:sharedUserId="android.uid.system"
android:vmSafeMode 启用虚拟机安全模式(禁用 JIT) 28 android:vmSafeMode="true" 用于调试性能问题

四、 多进程与组件类属性

属性 用途 最低API 是否过时 示例 兼容性说明
android:process 指定全局进程名 1 android:process=":remote" : 前缀表示私有进程
android:appComponentFactory 自定义组件(Activity/Service)实例化逻辑 28 android:appComponentFactory="androidx.core.app.CoreComponentFactory" 需实现 android.app.AppComponentFactory
android:zygotePreloadName 指定 Zygote 预加载进程名(系统优化) 28 android:zygotePreloadName="webview_zygote" 仅供系统应用使用

五、新兴特性类属性 (API 30+)

属性 用途 最低API 是否过时 示例 兼容性说明
android:enableOnBackInvokedCallback 启用系统返回手势的 Jetpack 回调 33 android:enableOnBackInvokedCallback="true" 需配合 OnBackInvokedDispatcher 使用
android:requestForegroundServiceExemption 申请前台服务豁免(免显示通知) 35 android:requestForegroundServiceExemption="mediaPlayback" 需满足特定 豁免条件
android:enableVrMode 启用 VR 模式(沉浸式头显支持) 24 android:enableVrMode="true" 需声明 android.permission.ACCESS_VR_MANAGER

六、Android 35 配置示例

xml 复制代码
<application
    android:name=".MyApplication"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme"
    android:networkSecurityConfig="@xml/network_security"
    android:hardwareAccelerated="true"
    android:requestForegroundServiceExemption="mediaPlayback"
    android:allowBackup="false"
    tools:targetApi="35">

    <!-- API 29~30 分区存储兼容 -->
    <meta-data
        android:name="android:requestLegacyExternalStorage"
        android:value="true"
        tools:targetApi="30"/>

    <!-- 组件声明 -->
    <activity android:name=".MainActivity" />
</application>

七、 兼容性适配建议

1. 分区存储过渡

  • API 31+ 必须使用 MediaStore 或 SAF (存储访问框架)
  • 使用 Context#getExternalFilesDir() 访问应用专属目录

2. 网络安全策略

xml 复制代码
<!-- res/xml/network_security.xml -->
<network-security-config>
    <base-config cleartextTrafficPermitted="false"/>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">insecure.example.com</domain>
    </domain-config>
</network-security-config>

3. 返回手势兼容

kotlin 复制代码
if (Build.VERSION.SDK_INT >= 33) {
    onBackInvokedDispatcher.registerCallback(backCallback)
} else {
    onBackPressedDispatcher.addCallback(backCallback)
}

通过合理配置这些属性,可在 Android 35 设备上实现最佳性能与安全特性,同时保持对旧版本系统的兼容。

更多分享

  1. Android 存储权限兼容问题详解 ------ 新手指南
  2. Android 定位权限兼容问题详解 ------ 新手指南
  3. Parcelable 和 Serializable 的区别详解 ------ 新手指南
  4. Android 事件分发机制详解 ------ 新手指南
  5. Android Executor 与 Executors 详解 ------ 新手指南
相关推荐
liang_jy1 天前
Android SparseArray
android·源码
liang_jy1 天前
Activity 启动流程扩展篇(一)—— startActivityInner 任务决策全解析
android·源码
NPE~1 天前
[App逆向]脱壳实战
android·教程·逆向·android逆向·逆向分析
木易 士心1 天前
别再只会用 drawCircle 了!一文搞懂 Android Canvas 底层机制
android
AtOR CUES1 天前
MySQL——表操作及查询
android·mysql·adb
怣疯knight1 天前
安卓App无法增加自定义图片作为图标功能
android
jinanwuhuaguo1 天前
OpenClaw联邦之心——从孤岛记忆到硅基集体潜意识的拓扑学革命(第二十三篇)
android·人工智能·kotlin·拓扑学·openclaw
Gary Studio1 天前
安卓HAL C++基础-命名域
android
诸神黄昏EX1 天前
Android Google XTS
android
eSsO KERF1 天前
MySQL Workbench菜单汉化为中文
android·数据库·mysql