手动构建和运行可分析应用
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
如需手动构建可分析应用,您需要先构建发布版应用,然后更新其清单文件,将发布版应用转换为可分析应用。在您之后
配置可分析应用,启动性能分析器并选择
可分析进程
构建发布版应用
如需出于性能分析目的构建发布版应用,请执行以下操作:
-
使用调试密钥为应用签名,方法是将以下几行代码添加到应用的 build.gradle
文件。如果您已有有效的发布 build 变体,则可以跳到下一步。
buildTypes {
release {
signingConfig signingConfigs.debug
}
}
-
在 Android Studio 中,依次选择 Build > Select Build Variant...,然后选择发布变体。
将发布版应用更改为可分析应用
如需将发布版应用转换为可分析应用,请执行以下操作:
以下:
-
打开
AndroidManifest.xml
文件,并在该文件中添加以下代码
<application>
。如需了解详情,请参阅构建应用以进行发布。
<profileable android:shell="true"/>
-
您可能会看到与清单验证相关的错误,具体取决于 SDK 版本;如果您无法解决这些错误,并且认为将这些错误视为警告是安全的,可以将以下几行代码添加到 build.gradle
文件中。
aaptOptions {
additionalParameters =["--warn-manifest-validation"]
}
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[null,null,["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# Build and run a profileable app manually\n\nTo build a [profileable](/studio/profile#requirements) application manually, you\nneed to first build a release application and then update its manifest file,\nwhich turns the release application into a profileable application. After you\nconfigure the profileable application, launch the profiler and select a\nprofileable process to analyze.\n\nBuild a release app\n-------------------\n\nTo build a release application for profiling purposes, do the following:\n\n\u003cbr /\u003e\n\n1. Sign your application with the debug key by adding the following lines to your application's\n `build.gradle` file. If you already have a working release build variant, you can\n skip to the next step.\n\n buildTypes {\n release {\n signingConfig signingConfigs.debug\n }\n }\n \n2. In Android Studio, select **Build** \\\u003e **Select Build Variant...** and choose the\n release variant.\n\n\u003cbr /\u003e\n\nChange release to profileable\n-----------------------------\n\nTo convert your [release app](#build-release-app) to a profileable app, do the\nfollowing:\n\n1. Open the\n `AndroidManifest.xml` file and adding the following within\n `\u003capplication\u003e`. For more details, see\n [Build your app for release](/studio/publish/preparing#publishing-build).\n\n `\u003cprofileable android:shell=\"true\"/\u003e`\n2. Depending on the SDK version, you might see an error related to manifest\n validation; if you can't resolve them and deem it safe to treat the errors\n as warnings, you can do so by adding the following lines to your\n `build.gradle` file.\n\n aaptOptions {\n additionalParameters =[\"--warn-manifest-validation\"]\n }"]]