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 详解 ------ 新手指南
相关推荐
花卷HJ20 小时前
Android 通用 RecyclerView Adapter 实现(支持 ViewBinding + 泛型 + 点击事件)
android
oMcLin20 小时前
如何在Ubuntu 22.04 LTS上配置并优化MySQL 8.0分区表,提高大规模数据集查询的效率与性能?
android·mysql·ubuntu
幸福的达哥21 小时前
安卓APP代码覆盖率测试方案
android·代码覆盖率
佛系打工仔21 小时前
绘制K线入门
android
得物技术1 天前
得物App智能巡检技术的探索与实践
app·客户端
川石课堂软件测试1 天前
Android和iOS APP平台测试的区别
android·数据库·ios·oracle·单元测试·测试用例·cocoa
花卷HJ1 天前
Android 通用 BaseDialog 实现:支持 ViewBinding + 全屏布局 + 加载弹窗
android
生产队队长1 天前
Linux:awk进行行列转换操作
android·linux·运维
大熊猫侯佩1 天前
App 暴毙现场直击:如何用 MetricKit 写一份完美的“验尸报告”
app·xcode·apple
叶羽西1 天前
Android15 EVS HAL中使用Camera HAL Provider接口
android