|
1 | | -Android(Mac) 打包 |
| 1 | +Android 打包 |
2 | 2 | === |
| 3 | +官方教程 https://reactnative.dev/docs/signed-apk-android/ |
3 | 4 |
|
4 | | -> 🚧 Android(Mac)打包前需要先准备好`需要打包的项目`<!--rehype:style=color: #1c7bd0; background: ##E6E6E6--> 及 `Android Studio`<!--rehype:style=color: #1c7bd0; background: ##E6E6E6-->。 |
5 | | -<!--rehype:style=border-left: 8px solid #ffe564;background-color: #ffe56440;padding: 12px 16px;--> |
| 5 | +Android要求所有应用都必须先使用证书进行数字签名,然后才能安装。 为了通过Google Play商店分发您的Android应用,需要使用发布密钥对其进行签名,然后再将其用于以后的所有更新。 自2017年以来,借助Google Play的应用签名功能,Google Play可以自动管理签名发布。 但是,在将应用程序二进制文件上传到Google Play之前,需要使用上传密钥对其进行签名。 Android Developers文档上的[“签署应用程序”](https://developer.android.com/tools/publishing/app-signing.html)页面详细描述了该主题。 本指南简要介绍了该过程,并列出了打包JavaScript捆绑包所需的步骤。 |
| 6 | + |
| 7 | +## 生成上传需要的秘钥 |
| 8 | + |
| 9 | +> Android要求所有应用都有一个数字签名才会被允许安装在用户手机上,Android开发者官网上的如何给你的 [应用签名文档](https://developer.android.com/tools/publishing/app-signing.html) 描述了签名的细节 |
| 10 | +
|
| 11 | +生成签名有两种方式: |
| 12 | + |
| 13 | +- Keytool命令行 |
| 14 | +- Android Studio界面生成 |
6 | 15 |
|
| 16 | +# Android Studio界面生成 |
7 | 17 | ## 一. 创建签名文件 |
8 | 18 |
|
9 | 19 | ### `创建签名文件`<!--rehype:style=color: white; background: #1c7bd0;--> |
@@ -35,4 +45,70 @@ Android(Mac) 打包 |
35 | 45 | > 密钥库文件地址在项目`Android/app/debug.keystore`<!--rehype:style=color: #1c7bd0; background: ##E6E6E6-->目录下。 |
36 | 46 | <!--rehype:style=border-left: 8px solid #ffe564;background-color: #ffe56440;padding: 12px 16px;--> |
37 | 47 |
|
38 | | -文档正在建设中... |
| 48 | +# Keytool命令行生成 |
| 49 | +您可以使用keytool生成专用签名密钥。 在Windows上,必须从 `C:\Program Files\Java\jdkx.x.x_x\bin` 运行keytool。 |
| 50 | + |
| 51 | +```shell |
| 52 | +$ keytool -genkeypair -v -keystore xx-key.keystore -alias xx-key-alias -keyalg RSA -keysize 2048 -validity 10000 |
| 53 | +``` |
| 54 | + |
| 55 | +⚠️ 生成打包用的 key,将 `keystore` 命名为 `xx-release-key.keystore` 别名 `-alias` 为 `xx-key-alias` |
| 56 | +⚠️ 记住要输入的 `输入密钥库口令:` |
| 57 | + |
| 58 | +```shell |
| 59 | +keytool -genkeypair -v -keystore xx-release-key.keystore -alias xx-key-alias -keyalg RSA -keysize 2048 -validity 10000 |
| 60 | +# 输入密钥库口令: 123456 |
| 61 | +# 再次输入新口令: |
| 62 | +# 您的名字与姓氏是什么? |
| 63 | +# [Unknown]: Wang |
| 64 | +# 您的组织单位名称是什么? |
| 65 | +# [Unknown]: junzhuo |
| 66 | +# 您的组织名称是什么? |
| 67 | +# [Unknown]: junzhuo |
| 68 | +# 您所在的城市或区域名称是什么? |
| 69 | +# [Unknown]: shanghai |
| 70 | +# 您所在的省/市/自治区名称是什么? |
| 71 | +# [Unknown]: shanghai |
| 72 | +# 该单位的双字母国家/地区代码是什么? |
| 73 | +# [Unknown]: zh |
| 74 | +# CN=Wang, OU=junzhuo, O=junzhuo, L=shanghai, ST=shanghai, C=zh是否正确? |
| 75 | +# [否]: y |
| 76 | +# |
| 77 | +# 正在为以下对象生成 2,048 位RSA密钥对和自签名证书 (SHA256withRSA) (有效期为 10,000 天): |
| 78 | +# CN=Wang, OU=junzhuo, O=junzhuo, L=shanghai, ST=shanghai, C=zh |
| 79 | +# 输入 <xx-key-alias> 的密钥口令 |
| 80 | +# (如果和密钥库口令相同, 按回车): |
| 81 | +# [正在存储goods-key.keystore] |
| 82 | +# |
| 83 | +# 这是一个巨坑 不要迁移标准格式,否则打包错误 |
| 84 | +# Warning: |
| 85 | +# JKS 密钥库使用专用格式。建议使用 "keytool -importkeystore -srckeystore xx-key.keystore -destkeystore xx-key.keystore -deststoretype pkcs12" 迁移到行业标准格式 PKCS12。 |
| 86 | +``` |
| 87 | + |
| 88 | +⚠️⚠️⚠️ 下面这是一个巨坑 不要迁移标准格式,否则打包错误,上面生成命令会提示下面命令,如果你照做了,坑可能爬不出来 |
| 89 | + |
| 90 | +```shell |
| 91 | +# Warning: |
| 92 | +# JKS 密钥库使用专用格式。建议使用 " |
| 93 | +keytool -importkeystore -srckeystore xx-key.keystore -destkeystore xx-key.keystore -deststoretype pkcs12 |
| 94 | +# " 迁移到行业标准格式 PKCS12。 |
| 95 | +``` |
| 96 | + |
| 97 | +## 设置Gradle变量 |
| 98 | +<!--rehype:style=max-width: 650px;width: 100%;--> |
| 99 | + |
| 100 | +如果 Gradle 加载失败,https://gradle.org/ 点击下面按钮重新同步 |
| 101 | + |
| 102 | +<!--rehype:style=max-width: 650px;width: 100%;--> |
| 103 | + |
| 104 | +Android Studio 打包 |
| 105 | + |
| 106 | +<!--rehype:style=max-width: 650px;width: 100%;--> |
| 107 | + |
| 108 | +<!--rehype:style=max-width: 650px;width: 100%;--> |
| 109 | + |
| 110 | +<!--rehype:style=max-width: 650px;width: 100%;--> |
| 111 | + |
| 112 | +记得选择生成目录 `<项目所在目录>/android/app/build/outputs/apk` |
| 113 | + |
| 114 | +<!--rehype:style=max-width: 650px;width: 100%;--> |
0 commit comments