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 详解 ------ 新手指南
相关推荐
feathered-feathered2 小时前
Redis【事务】(面试相关)与MySQL相比较,重点在Redis事务
android·java·redis·后端·mysql·中间件·面试
Kapaseker2 小时前
三分钟搞懂 Kotlin Flow 中的背压
android·kotlin
柯南二号2 小时前
【大前端】【Android】把 Activity 重构成 MVVM 的对比示例
android·状态模式
某空m2 小时前
【Android】Glide的缓存机制
android·缓存·glide
某空m2 小时前
【Android】Glide的使用
android·glide
QING6182 小时前
Jetpack Compose 中的 ViewModel 作用域管理 —— 新手指南
android·kotlin·android jetpack
鹏多多3 小时前
flutter-使用EventBus实现组件间数据通信
android·前端·flutter
ShayneLee83 小时前
Nginx修改请求头响应头
android·运维·nginx
廋到被风吹走3 小时前
【数据库】【MySQL】高可用与扩展方案深度解析
android·数据库·mysql
恋猫de小郭3 小时前
Flutter 官方正式解决 WebView 在 iOS 26 上有点击问题
android·前端·flutter