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 详解 ------ 新手指南
相关推荐
三少爷的鞋7 小时前
Android 架构七条铁律:架构师真正设计的不是代码,而是秩序
android
xiangxiongfly9158 小时前
Android GsonFactory总结
android·gson·gsonfactory
WythePlus10 小时前
Android 14 SELinux策略深度解析
android·安全策略·selinux策略
俩个逗号。。13 小时前
Kotlin flow 详解
android·开发语言·kotlin
茶底世界之下15 小时前
斜光下的旧自行车:用 Awaking 留一版复古胶片色
ios·app·产品
橙光成长15 小时前
android-ad-cleaner:android免 Root 批量关闭系统开屏与营销推送
android·1024程序员节
深圳雨林凯AI15 小时前
图案裂变的底色衰减:alpha通道、亮度对比与白墨分色的量化拆解
android
mmsx16 小时前
Android 模块化收口:能力组合框架、手写 LifecycleOwner 与热修复共存
android
恋猫de小郭18 小时前
Flutter 可以更直接地调用原生 API 了,Dart Direct Native Interop
android·前端·flutter
2501_9160088918 小时前
iPhone 设备信息查看,用 KeyMob 看型号、序列号、电池健康和 UDID
android·ios·小程序·https·uni-app·iphone·webview