Skip to content

Commit bbf3c42

Browse files
committedJul 5, 2023
doc: update android packaging.
1 parent a951de9 commit bbf3c42

File tree

8 files changed

+59
-25
lines changed

8 files changed

+59
-25
lines changed
 

‎website/src/pages/docs/unpack/android/README.md

+59-25
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ Android 打包
66
Android要求所有应用都必须先使用证书进行数字签名,然后才能安装。 为了通过Google Play商店分发您的Android应用,需要使用发布密钥对其进行签名,然后再将其用于以后的所有更新。 自2017年以来,借助Google Play的应用签名功能,Google Play可以自动管理签名发布。 但是,在将应用程序二进制文件上传到Google Play之前,需要使用上传密钥对其进行签名。 Android Developers文档上的[“签署应用程序”](https://developer.android.com/tools/publishing/app-signing.html)页面详细描述了该主题。 本指南简要介绍了该过程,并列出了打包JavaScript捆绑包所需的步骤。
77

88
## 打包修改 APP 版本号
9+
910
### 修改 `android/app/build.gradle` 配置
1011

11-
```xml
12+
```java
1213
android {
1314
.....
1415
defaultConfig {
@@ -18,38 +19,70 @@ android {
1819
}
1920
```
2021

21-
## Android9.0以上打包APK后HTTP请求不到解决方法
22+
## Android9.0 以上打包APK后HTTP请求不到解决方法
23+
24+
错误原因:`android9.0` 默认禁止访问不安全的请求,比如 `http`
2225

23-
错误原因:android9.0默认禁止访问不安全的请求,比如http。
26+
### 解决方法 `1`
2427

25-
### 解决方案:
26-
方法1: 使用认证过的https(我用的是阿里云免费证书,因为使用https还得配置,所以用了http)
28+
使用认证过的 `https`(我用的是阿里云免费证书,因为使用 `https` 还得配置,所以用了 `http`
2729

28-
方法2: 分为两步
30+
### 解决方法 `2`
2931

30-
第一步:在res下新增加一个xml目录,然后创建一个名为network_security_config.xml文件
32+
添加配置强制支持 `http`
33+
34+
#### 第一步:
35+
36+
`res` 下新增加一个 `xml` 目录,然后创建一个名为 `network_security_config.xml` 文件
3137

3238
![](./img/image6.png)<!--rehype:style=max-width: 650px;width: 100%;-->
3339

34-
```bash
40+
```xml
3541
<?xml version="1.0" encoding="utf-8"?>
3642
<network-security-config>
37-
<base-config cleartextTrafficPermitted="true" />
43+
<base-config cleartextTrafficPermitted="true" />
3844
</network-security-config>
3945
```
4046

41-
第二步:
42-
43-
在androidManifiest.xml文件中添加
44-
```bash
45-
android:networkSecurityConfig="@xml/network_security_config"
47+
#### 第二步:
48+
49+
`android/app/src/main/AndroidManifest.xml` 文件中添加
50+
51+
```diff
52+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
53+
<uses-permission android:name="android.permission.INTERNET" />
54+
<uses-permission android:name="android.permission.CAMERA" />
55+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
56+
57+
<application
58+
android:name=".MainApplication"
59+
android:label="@string/app_name"
60+
android:icon="@mipmap/ic_launcher"
61+
android:allowBackup="false"
62+
+ android:networkSecurityConfig="@xml/network_security_config"
63+
android:theme="@style/AppTheme">
64+
<activity
65+
android:name=".MainActivity"
66+
android:label="@string/app_name"
67+
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
68+
android:launchMode="singleTask"
69+
android:windowSoftInputMode="adjustResize"
70+
android:exported="true">
71+
<intent-filter>
72+
<action android:name="android.intent.action.MAIN" />
73+
<category android:name="android.intent.category.LAUNCHER" />
74+
</intent-filter>
75+
</activity>
76+
</application>
77+
</manifest>
4678
```
79+
4780
![](./img/image7.png)<!--rehype:style=max-width: 650px;width: 100%;-->
4881

4982
> ⚠️ 下面还有一种方式 本质上跟第二种方法一样,简便但不规范 建议用上面的方法<!--rehype:style=background: #F08800; color: #fff;-->
5083
<!--rehype:style=border-left: 8px solid #ffe564;background-color: #ffe56440;padding: 12px 16px;-->
5184
52-
在项目/android/app/src/main/AndroidManifest.xml文件中的application节点下添加
85+
在项目 `/android/app/src/main/AndroidManifest.xml` 文件中的 `application` 节点下添加
5386

5487
```bash
5588
android:usesCleartextTraffic="true"
@@ -66,39 +99,39 @@ android:usesCleartextTraffic="true"
6699
- Keytool命令行
67100
- Android Studio界面生成
68101

69-
# Android Studio界面生成
70-
## 一. 创建签名文件
102+
### Android Studio 界面生成
71103

72-
### `创建签名文件`<!--rehype:style=color: white; background: #1c7bd0;-->
104+
#### `创建签名文件`<!--rehype:style=color: white; background: #1c7bd0;-->
73105

74-
`Android Studio`<!--rehype:style=color: #1c7bd0; background: ##E6E6E6-->打开需要打包的项目,之后选择 `Build`<!--rehype:style=color: #1c7bd0; background: ##E6E6E6-->中的`Generate Signed Bundle/APK`<!--rehype:style=color: #1c7bd0; background: ##E6E6E6-->开始创建签名文件。
106+
`Android Studio`<!--rehype:style=color: #1c7bd0; background: ##E6E6E6-->打开需要打包的项目,之后选择 `Build`<!--rehype:style=color: #1c7bd0; background: ##E6E6E6-->中的 `Generate Signed Bundle/APK`<!--rehype:style=color: #1c7bd0; background: ##E6E6E6-->开始创建签名文件。
75107

76108
![](./img/01.png)<!--rehype:style=max-width: 650px;width: 100%;-->
77109

78110
选择`Android App Bundle`<!--rehype:style=color: #1c7bd0; background: ##E6E6E6-->点击进入下一步。
79111

80112
![](./img/02.png)<!--rehype:style=max-width: 650px;width: 100%;-->
81113

82-
### `填写签名参数`<!--rehype:style=color: white; background: #1c7bd0;-->
114+
#### `填写签名参数`<!--rehype:style=color: white; background: #1c7bd0;-->
83115

84116
![](./img/03.png)<!--rehype:style=max-width: 650px;width: 100%;-->
85117

86-
#### `1. 创建密钥库(已拥有密钥库跳过)`<!--rehype:style=color: white; background: #ffb703;-->
118+
##### `1. 创建密钥库(已拥有密钥库跳过)`<!--rehype:style=color: white; background: #ffb703;-->
87119

88120
点击`Create new...”`<!--rehype:style=color: #1c7bd0; background: ##E6E6E6-->按钮创建密钥库,填写相关信息后,点击`OK`创建成功。
89121

90122
![](./img/04.png)<!--rehype:style=max-width: 650px;width: 100%;-->
91123

92-
#### `2.选择已存在密钥库及密钥`<!--rehype:style=color: white; background: #ffb703;-->
124+
##### `2.选择已存在密钥库及密钥`<!--rehype:style=color: white; background: #ffb703;-->
93125

94126
点击`Choose existing...”`<!--rehype:style=color: #1c7bd0; background: ##E6E6E6-->按钮找到密钥库文件。
95127

96128
![](./img/05.png)<!--rehype:style=max-width: 650px;width: 100%;-->
97129

98-
> 密钥库文件地址在项目`Android/app/debug.keystore`<!--rehype:style=color: #1c7bd0; background: ##E6E6E6-->目录下。
130+
> 密钥库文件地址在项目`Android/app/debug.keystore`<!--rehype:style=color: #1c7bd0; background: ##E6E6E6-->目录下。如果自己生成,请记住目录在生成的目录中找 `*.keystore` 密钥文件
99131
<!--rehype:style=border-left: 8px solid #ffe564;background-color: #ffe56440;padding: 12px 16px;-->
100132
101-
# Keytool命令行生成
133+
### Keytool 命令行生成
134+
102135
您可以使用keytool生成专用签名密钥。 在Windows上,必须从 `C:\Program Files\Java\jdkx.x.x_x\bin` 运行keytool。
103136

104137
```shell
@@ -147,7 +180,8 @@ keytool -importkeystore -srckeystore xx-key.keystore -destkeystore xx-key.keysto
147180
# " 迁移到行业标准格式 PKCS12。
148181
```
149182

150-
## 设置Gradle变量
183+
### 设置 Gradle 变量
184+
151185
![](./img/image.png)<!--rehype:style=max-width: 650px;width: 100%;-->
152186

153187
如果 Gradle 加载失败,https://gradle.org/ 点击下面按钮重新同步
-285 KB
Loading
-268 KB
Loading
-341 KB
Loading
-365 KB
Loading
-264 KB
Loading
Loading
Loading

0 commit comments

Comments
 (0)
Please sign in to comment.