@@ -6,9 +6,10 @@ Android 打包
6
6
Android要求所有应用都必须先使用证书进行数字签名,然后才能安装。 为了通过Google Play商店分发您的Android应用,需要使用发布密钥对其进行签名,然后再将其用于以后的所有更新。 自2017年以来,借助Google Play的应用签名功能,Google Play可以自动管理签名发布。 但是,在将应用程序二进制文件上传到Google Play之前,需要使用上传密钥对其进行签名。 Android Developers文档上的[ “签署应用程序”] ( https://developer.android.com/tools/publishing/app-signing.html ) 页面详细描述了该主题。 本指南简要介绍了该过程,并列出了打包JavaScript捆绑包所需的步骤。
7
7
8
8
## 打包修改 APP 版本号
9
+
9
10
### 修改 ` android/app/build.gradle ` 配置
10
11
11
- ``` xml
12
+ ``` java
12
13
android {
13
14
.....
14
15
defaultConfig {
@@ -18,38 +19,70 @@ android {
18
19
}
19
20
```
20
21
21
- ## Android9.0以上打包APK后HTTP请求不到解决方法
22
+ ## Android9.0 以上打包APK后HTTP请求不到解决方法
23
+
24
+ 错误原因:` android9.0 ` 默认禁止访问不安全的请求,比如 ` http ` 。
22
25
23
- 错误原因:android9.0默认禁止访问不安全的请求,比如http。
26
+ ### 解决方法 ` 1 ` :
24
27
25
- ### 解决方案:
26
- 方法1: 使用认证过的https(我用的是阿里云免费证书,因为使用https还得配置,所以用了http)
28
+ 使用认证过的 ` https ` (我用的是阿里云免费证书,因为使用 ` https ` 还得配置,所以用了 ` http ` )
27
29
28
- 方法2: 分为两步
30
+ ### 解决方法 ` 2 ` :
29
31
30
- 第一步:在res下新增加一个xml目录,然后创建一个名为network_security_config.xml文件
32
+ 添加配置强制支持 ` http `
33
+
34
+ #### 第一步:
35
+
36
+ 在 ` res ` 下新增加一个 ` xml ` 目录,然后创建一个名为 ` network_security_config.xml ` 文件
31
37
32
38
![ ] ( ./img/image6.png ) <!-- rehype:style=max-width: 650px;width: 100%;-->
33
39
34
- ``` bash
40
+ ``` xml
35
41
<?xml version =" 1.0" encoding =" utf-8" ?>
36
42
<network-security-config >
37
- < base-config cleartextTrafficPermitted=" true" />
43
+ <base-config cleartextTrafficPermitted =" true" />
38
44
</network-security-config >
39
45
```
40
46
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>
46
78
```
79
+
47
80
![ ] ( ./img/image7.png ) <!-- rehype:style=max-width: 650px;width: 100%;-->
48
81
49
82
> ⚠️ 下面还有一种方式 本质上跟第二种方法一样,简便但不规范 建议用上面的方法<!-- rehype:style=background: #F08800; color: #fff;-->
50
83
<!--rehype:style=border-left: 8px solid #ffe564;background-color: #ffe56440;padding: 12px 16px;-->
51
84
52
- 在项目/android/app/src/main/AndroidManifest.xml文件中的application节点下添加
85
+ 在项目 ` /android/app/src/main/AndroidManifest.xml ` 文件中的 ` application ` 节点下添加
53
86
54
87
``` bash
55
88
android:usesCleartextTraffic=" true"
@@ -66,39 +99,39 @@ android:usesCleartextTraffic="true"
66
99
- Keytool命令行
67
100
- Android Studio界面生成
68
101
69
- # Android Studio界面生成
70
- ## 一. 创建签名文件
102
+ ### Android Studio 界面生成
71
103
72
- ### ` 创建签名文件 ` <!-- rehype:style=color: white; background: #1c7bd0;-->
104
+ #### ` 创建签名文件 ` <!-- rehype:style=color: white; background: #1c7bd0;-->
73
105
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--> 开始创建签名文件。
75
107
76
108
![ ] ( ./img/01.png ) <!-- rehype:style=max-width: 650px;width: 100%;-->
77
109
78
110
选择` Android App Bundle ` <!-- rehype:style=color: #1c7bd0; background: ##E6E6E6--> 点击进入下一步。
79
111
80
112
![ ] ( ./img/02.png ) <!-- rehype:style=max-width: 650px;width: 100%;-->
81
113
82
- ### ` 填写签名参数 ` <!-- rehype:style=color: white; background: #1c7bd0;-->
114
+ #### ` 填写签名参数 ` <!-- rehype:style=color: white; background: #1c7bd0;-->
83
115
84
116
![ ] ( ./img/03.png ) <!-- rehype:style=max-width: 650px;width: 100%;-->
85
117
86
- #### ` 1. 创建密钥库(已拥有密钥库跳过) ` <!-- rehype:style=color: white; background: #ffb703;-->
118
+ ##### ` 1. 创建密钥库(已拥有密钥库跳过) ` <!-- rehype:style=color: white; background: #ffb703;-->
87
119
88
120
点击` Create new...” ` <!-- rehype:style=color: #1c7bd0; background: ##E6E6E6--> 按钮创建密钥库,填写相关信息后,点击` OK ` 创建成功。
89
121
90
122
![ ] ( ./img/04.png ) <!-- rehype:style=max-width: 650px;width: 100%;-->
91
123
92
- #### ` 2.选择已存在密钥库及密钥 ` <!-- rehype:style=color: white; background: #ffb703;-->
124
+ ##### ` 2.选择已存在密钥库及密钥 ` <!-- rehype:style=color: white; background: #ffb703;-->
93
125
94
126
点击` Choose existing...” ` <!-- rehype:style=color: #1c7bd0; background: ##E6E6E6--> 按钮找到密钥库文件。
95
127
96
128
![ ] ( ./img/05.png ) <!-- rehype:style=max-width: 650px;width: 100%;-->
97
129
98
- > 密钥库文件地址在项目` Android/app/debug.keystore ` <!-- rehype:style=color: #1c7bd0; background: ##E6E6E6--> 目录下。
130
+ > 密钥库文件地址在项目` Android/app/debug.keystore ` <!-- rehype:style=color: #1c7bd0; background: ##E6E6E6--> 目录下。如果自己生成,请记住目录在生成的目录中找 ` *.keystore ` 密钥文件
99
131
<!--rehype:style=border-left: 8px solid #ffe564;background-color: #ffe56440;padding: 12px 16px;-->
100
132
101
- # Keytool命令行生成
133
+ ### Keytool 命令行生成
134
+
102
135
您可以使用keytool生成专用签名密钥。 在Windows上,必须从 ` C:\Program Files\Java\jdkx.x.x_x\bin ` 运行keytool。
103
136
104
137
``` shell
@@ -147,7 +180,8 @@ keytool -importkeystore -srckeystore xx-key.keystore -destkeystore xx-key.keysto
147
180
# " 迁移到行业标准格式 PKCS12。
148
181
```
149
182
150
- ## 设置Gradle变量
183
+ ### 设置 Gradle 变量
184
+
151
185
![ ] ( ./img/image.png ) <!-- rehype:style=max-width: 650px;width: 100%;-->
152
186
153
187
如果 Gradle 加载失败,https://gradle.org/ 点击下面按钮重新同步
0 commit comments