- 语法:
<profileable android:shell=["true" | "false"] android:enabled=["true" | "false"] />
- 包含于:
<application>
- 说明:
- 指定性能分析器如何访问此应用。
- 属性:
android:shell
-
指定设备用户能否使用如下本地调试工具分析此应用的性能:
android.os.Trace
跟踪 API(Android 11 及更低版本)simpleperf
am profile
命令perfetto
性能分析器(原生内存、Java 内存、CPU)
false
,则这些工具和 API 仅在应用处于debuggable
状态时可以正常使用。 可调试的应用会导致性能出现各种明显的下降,对准确衡量时间并无帮助。强烈建议在本地性能测量中使用该元素以获得准确的结果。此元素旨在用于发布或正式发布 build,以便启用本地性能分析功能。它几乎不会引起数据泄露:主机分析工具和 shell 进程都无法读取任何内存数据。只有堆栈轨迹是可读取的,而堆栈轨迹在发布 build 中通常经过混淆处理或缺少符号。
android:enabled
- 指定系统服务或 shell 工具能否对应用进行性能分析。
对于后者,还需要设置
android:shell
。 如果为 false,则根本无法对该应用进行性能分析。默认值为 true。 该属性是 API 级别 30 中的新增属性。
- 引入于:
- API 级别 29
<可分析>
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[null,null,["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# <profileable\u003e\n\nsyntax:\n:\n\n ```xml\n \u003cprofileable android:shell=[\"true\" | \"false\"] android:enabled=[\"true\" | \"false\"] /\u003e\n ```\n\ncontained in:\n: [\u003capplication\u003e](/guide/topics/manifest/application-element)\n\ndescription:\n: Specifies how profilers can access this application.\n\nattributes:\n:\n\n `android:shell`\n :\n Specifies whether the user of the device can profile this application through local debugging\n tools such as the following:\n\n - [android.os.Trace](/reference/kotlin/android/os/Trace) tracing APIs (Android 11 and lower)\n - [simpleperf](/ndk/guides/simpleperf)\n - [am profile](/studio/command-line/adb#am) commands\n - [`perfetto` profilers](/studio/command-line/perfetto) (native memory, Java memory, CPU)\n\n\n If this isn't set, or is set to `false`, these tools and APIs work only when an app is\n [debuggable](/guide/topics/manifest/application-element#debug).\n Debuggable apps incur significant and varied performance degradation and aren't useful for\n measuring timing accurately. This element is strongly recommended for local performance\n measurements, to capture accurate results.\n\n This element is designed to be usable in release, or production, builds to enable local profiling.\n It incurs minimal risk of data exposure: no memory data is readable by the host profiling tools\n and the shell process. Only stack traces are readable, which are typically obfuscated or lacking symbols\n in release builds.\n\n:\n\n `android:enabled`\n :\n Specifies whether the application can be profiled by system services or shell tools.\n For the latter, you also set [`android:shell`](#shell).\n If false, the application can't be profiled at all. The default is true.\n\n This attribute was added in API level 30.\n\nintroduced in:\n: API Level 29"]]