# 部署

Android 允许您从任何地方（从网站、从任何商店等）在设备上安装应用。这是可能的，因为 Android 生态系统是开放的。然而，Google Play 是最著名、最受信任和最受欢迎的商店，由 Google 本身提供。如果用户想要从非受信任来源安装第三方应用，他们必须[通过设备安全设置明确允许](https://developer.android.com/studio/publish#publishing-unknown)。

## 部署调试版本

从高层次来看，调试版本部署包括以下步骤：

1. 生成（或访问）调试密钥库和证书。
2. 签名应用。
3. 在设备上安装应用。

如果设备允许从非受信任来源安装应用，则应用会启动。

当从 IDE 运行或调试项目时，Android Studio 会自动使用由 Android SDK 工具生成的调试证书对您的应用进行签名。当您第一次在 Android Studio 中运行或调试项目时，IDE 会自动在 `$HOME/.android/debug.keystore` 中创建调试密钥库和证书，并设置密钥库和密钥密码。

因为调试证书是由构建工具创建的，并且设计上不安全，所以大多数应用商店（包括 Google Play 商店）不接受使用调试证书签名的应用用于发布。

## 部署发布版本

从高层次来看，将发布版本部署到 Google Play 包括以下步骤：

1. 创建 Google Play 开发者帐户。
2. 生成（或访问）发布密钥库和证书。
3. 签名应用。
4. 将应用上传到 Google Play。

而其他供应商可能会在实际发布之前审查和批准应用，Google 只会扫描已知的恶意软件签名，这最小化了发布过程开始和公共应用可用性之间的时间。

### 签名密钥管理

Google Play 为开发者提供两个选项来管理其签名密钥：

* Play 应用签名
* 自行管理

#### Play 应用签名

使用 Play 应用签名，Google 为开发者管理和保护其应用签名密钥，并使用它来签署其 APK 进行分发。

![](/files/wrn4g5AC9PfLQNV04ShL)

Play 应用签名使用两个密钥：

* **应用签名密钥**用于签名安装在用户设备上的 APK。签名密钥在应用生命周期内永远不会更改。应用签名密钥是私有的，必须保密。
* **上传密钥**用于在上传到 Google Play 进行应用签名之前签名应用包或 APK。上传密钥是私有的，必须保密。

#### 自行管理

开发者可以管理自己的应用签名密钥和密钥库。当开发者签名其 APK 时，他们将使用其应用签名密钥在本地签名，并将签名的 APK 直接上传到 Google Play 商店进行分发。

![](/files/NydlXdGm4eFiwRNe8fty)

## 参考资料

* [Android 开发者：为您的应用签名](https://developer.android.com/studio/publish/app-signing)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://gitbook.cdxiaodong.life/android-ying-yong-an-quan/gai-shu/deployment.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
