@@ -2,8 +2,61 @@ Android 打包
22===
33官方教程 https://reactnative.dev/docs/signed-apk-android/
44
5+
56Android要求所有应用都必须先使用证书进行数字签名,然后才能安装。 为了通过Google Play商店分发您的Android应用,需要使用发布密钥对其进行签名,然后再将其用于以后的所有更新。 自2017年以来,借助Google Play的应用签名功能,Google Play可以自动管理签名发布。 但是,在将应用程序二进制文件上传到Google Play之前,需要使用上传密钥对其进行签名。 Android Developers文档上的[ “签署应用程序”] ( https://developer.android.com/tools/publishing/app-signing.html ) 页面详细描述了该主题。 本指南简要介绍了该过程,并列出了打包JavaScript捆绑包所需的步骤。
67
8+ ## 打包修改 APP 版本号
9+ ### 修改 ` android/app/build.gradle ` 配置
10+
11+ ``` xml
12+ android {
13+ .....
14+ defaultConfig {
15+ ....
16+ versionName "2.1.1"
17+ }
18+ }
19+ ```
20+
21+ ## Android9.0以上打包APK后HTTP请求不到解决方法
22+
23+ 错误原因:android9.0默认禁止访问不安全的请求,比如http。
24+
25+ ### 解决方案:
26+ 方法1: 使用认证过的https(我用的是阿里云免费证书,因为使用https还得配置,所以用了http)
27+
28+ 方法2: 分为两步
29+
30+ 第一步:在res下新增加一个xml目录,然后创建一个名为network_security_config.xml文件
31+
32+ ![ ] ( ./img/image6.png ) <!-- rehype:style=max-width: 650px;width: 100%;-->
33+
34+ ``` bash
35+ < ? xml version=" 1.0" encoding=" utf-8" ? >
36+ < network-security-config>
37+ < base-config cleartextTrafficPermitted=" true" />
38+ < /network-security-config>
39+ ```
40+
41+ 第二步:
42+
43+ 在androidManifiest.xml文件中添加
44+ ``` bash
45+ android:networkSecurityConfig=" @xml/network_security_config"
46+ ```
47+ ![ ] ( ./img/image7.png ) <!-- rehype:style=max-width: 650px;width: 100%;-->
48+
49+ > ⚠️ 下面还有一种方式 本质上跟第二种方法一样,简便但不规范 建议用上面的方法<!-- rehype:style=background: #F08800; color: #fff;-->
50+ <!--rehype:style=border-left: 8px solid #ffe564;background-color: #ffe56440;padding: 12px 16px;-->
51+
52+ 在项目/android/app/src/main/AndroidManifest.xml文件中的application节点下添加
53+
54+ ``` bash
55+ android:usesCleartextTraffic=" true"
56+ ```
57+
58+ ![ ] ( ./img/image8.png ) <!-- rehype:style=max-width: 650px;width: 100%;-->
59+
760## 生成上传需要的秘钥
861
962> Android要求所有应用都有一个数字签名才会被允许安装在用户手机上,Android开发者官网上的如何给你的 [ 应用签名文档] ( https://developer.android.com/tools/publishing/app-signing.html ) 描述了签名的细节
@@ -111,43 +164,4 @@ Android Studio 打包
111164
112165记得选择生成目录 ` <项目所在目录>/android/app/build/outputs/apk `
113166
114- ![ ] ( ./img/image5.png ) <!-- rehype:style=max-width: 650px;width: 100%;-->
115-
116- ## react-native android9.0以上打包APK后HTTP请求不到解决方法
117-
118- 错误原因:android9.0默认禁止访问不安全的请求,比如http。
119-
120- ### 解决方案:
121- 方法1: 使用认证过的https(我用的是阿里云免费证书,因为使用https还得配置,所以用了http)
122-
123- 方法2: 分为两步
124-
125- 第一步:在res下新增加一个xml目录,然后创建一个名为network_security_config.xml文件
126-
127- ![ ] ( ./img/image6.png ) <!-- rehype:style=max-width: 650px;width: 100%;-->
128-
129- ``` bash
130- < ? xml version=" 1.0" encoding=" utf-8" ? >
131- < network-security-config>
132- < base-config cleartextTrafficPermitted=" true" />
133- < /network-security-config>
134- ```
135-
136- 第二步:
137-
138- 在androidManifiest.xml文件中添加
139- ``` bash
140- android:networkSecurityConfig=" @xml/network_security_config"
141- ```
142- ![ ] ( ./img/image7.png ) <!-- rehype:style=max-width: 650px;width: 100%;-->
143-
144- > ⚠️ 下面还有一种方式 本质上跟第二种方法一样,简便但不规范 建议用上面的方法<!-- rehype:style=background: #F08800; color: #fff;-->
145- <!--rehype:style=border-left: 8px solid #ffe564;background-color: #ffe56440;padding: 12px 16px;-->
146-
147- 在项目/android/app/src/main/AndroidManifest.xml文件中的application节点下添加
148-
149- ``` bash
150- android:usesCleartextTraffic=" true"
151- ```
152-
153- ![ ] ( ./img/image8.png ) <!-- rehype:style=max-width: 650px;width: 100%;-->
167+ ![ ] ( ./img/image5.png ) <!-- rehype:style=max-width: 650px;width: 100%;-->
0 commit comments