File tree Expand file tree Collapse file tree 4 files changed +40
-1
lines changed
website/src/pages/docs/unpack/android Expand file tree Collapse file tree 4 files changed +40
-1
lines changed Original file line number Diff line number Diff line change @@ -111,4 +111,43 @@ Android Studio 打包
111111
112112记得选择生成目录 ` <项目所在目录>/android/app/build/outputs/apk `
113113
114- ![ ] ( ./img/image5.png ) <!-- rehype:style=max-width: 650px;width: 100%;-->
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%;-->
You can’t perform that action at this time.
0 commit comments