[英]React Native Android: Request works in android emulator, but not Play Store build
I have a React Native app that is making a simple sign in request. 我有一个React Native应用,正在进行简单的登录请求。 This request works in the ios simulator and works when I install the build onto my device. 此请求在ios模拟器中有效,并且在将构建安装到设备上时有效。 It does not work when I download the app from the Play Store. 当我从Play商店下载应用程序时,它不起作用。
I have tried the following: I have re-installed and installed the app. 我尝试了以下操作:我已经重新安装并安装了该应用程序。 Looked at production logs, I don't see any record that the request reaches the rails server. 查看生产日志,我看不到任何请求到达Rails服务器的记录。 I have been using bugsnag logging. 我一直在使用bugsnag日志记录。
Here is the request: 这是请求:
sendLoginEmail = (isResend) => {
bugsnag.notify(new Error(`1: ${this.state.email}`))
enterEmail(this.state.email).then(response => {
console.log("sle response!")
console.log(response)
bugsnag.notify(new Error(`2: ${this.state.email}`))
bugsnag.notify(new Error(JSON.stringify(response)))
if (response.status === 200) {
this.setState({isEmail: false, isLoading: false, warningMessage: isResend ? "Email resent" : null});
} else {
this.setState({isLoading: false, warningMessage: "Something went wrong. Please try again."})
}
}).catch(response => {
bugsnag.notify(new Error(JSON.stringify(response)))
})
}
enterEmail
looks like this: enterEmail
看起来像这样:
export const enterEmail = (email) => {
return fetch(`${host}/v2/users`, {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
user: {
email
}
})
})
}
Bugsnag logs the first error ( bugsnag.notify(new Error(
1: ${this.state.email} ))
) and catches the thrown error and logs the response. Bugsnag记录第一个错误( bugsnag.notify(new Error(
1:$ {this.state.email} ))
)并捕获引发的错误并记录响应。 The response shows the following line in index.android.bundle: new TypeError('Network request failed')
. 响应在index.android.bundle中显示以下行: new TypeError('Network request failed')
。
Here are my nginx.error.logs: 这是我的nginx.error.logs:
2019/08/23 09:57:46 [info] 885#885: *246 client closed connection while waiting for request, client: 124.251.44.162, server: 0.0.0.0:80
2019/08/23 10:01:44 [info] 885#885: *265 client 208.94.74.81 closed keepalive connection
2019/08/23 11:15:43 [info] 885#885: *267 client 103.208.200.14 closed keepalive connection
2019/08/23 14:03:38 [info] 885#885: *269 client 151.217.75.156 closed keepalive connection
2019/08/23 15:01:17 [info] 885#885: *271 client closed connection while waiting for request, client: 71.82.97.158, server: 0.0.0.0:80
2019/08/23 15:01:17 [info] 885#885: *272 client 71.82.97.158 closed keepalive connection (104: Connection reset by peer)
2019/08/23 17:18:01 [info] 885#885: *274 client 186.154.93.81 closed keepalive connection
2019/08/23 19:36:42 [info] 885#885: *276 client 47.62.114.44 closed keepalive connection (104: Connection reset by peer)
2019/08/23 19:37:19 [info] 885#885: *288 client 151.217.75.156 closed keepalive connection
2019/08/23 19:40:22 [info] 885#885: *311 client 47.62.114.44 closed keepalive connection (104: Connection reset by peer)
2019/08/23 19:42:05 [info] 885#885: *341 client 47.62.114.44 closed keepalive connection (104: Connection reset by peer)
2019/08/23 19:42:05 [info] 885#885: *339 client 47.62.114.44 closed keepalive connection (104: Connection reset by peer)
2019/08/23 19:42:05 [info] 885#885: *332 client 47.62.114.44 closed keepalive connection (104: Connection reset by peer)
2019/08/23 19:42:05 [info] 885#885: *335 client 47.62.114.44 closed keepalive connection (104: Connection reset by peer)
2019/08/23 19:44:52 [info] 885#885: *348 client 47.62.114.44 closed keepalive connection (104: Connection reset by peer)
2019/08/23 20:51:07 [info] 885#885: *352 client 84.41.107.234 closed keepalive connection
2019/08/23 21:23:54 [info] 885#885: *354 client 181.118.94.19 closed keepalive connection
2019/08/23 22:02:16 [info] 885#885: *356 client 138.122.20.90 closed keepalive connection
2019/08/23 22:47:07 [info] 885#885: *358 client sent invalid method while reading client request line, client: 61.219.11.153, server: , request: ""
2019/08/23 22:56:28 [info] 885#885: *359 client 150.242.255.221 closed keepalive connection
I suspect there's some problem with my nginx configuration, but I don't know what it is. 我怀疑我的nginx配置有问题,但我不知道它是什么。
I guess the production / debug android versions are different in someway, which would explain why the request works on my device when installed from android studio, but not from the play store. 我猜生产/调试android版本有所不同,这可以解释为什么当从android studio安装而不是从Play商店安装时,请求在我的设备上起作用的原因。 I don't know what that difference is. 我不知道那是什么区别。
Thanks. 谢谢。
This is the issue with signed Apk 这是签名Apk的问题
Delete your android/build folder, ./gradle file 删除您的android / build文件夹,。/ gradle文件
Generate a debug Apk 生成调试Apk
Then generate signed Apk 然后生成签名的Apk
This might also be a proguard issue. 这也可能是一个保护问题。 It might work on 32 bit and fail on 64 bit or vice versa. 它可能在32位上工作,而在64位上失败,反之亦然。
The problem was that Android now defaults to only allowing requests over HTTPS. 问题在于,Android现在默认情况下仅允许通过HTTPS进行请求。 My request was sent over HTTP. 我的请求是通过HTTP发送的。 When this happens, the request fails silently. 发生这种情况时,请求将以静默方式失败。
To allow HTTP requests add the following to application
your manifest ( AndroidManifest.xml
): android:usesCleartextTraffic="true"
要允许HTTP请求中添加以下application
的清单( AndroidManifest.xml
): android:usesCleartextTraffic="true"
Alternatively, you can make the request over HTTPS. 或者,您可以通过HTTPS发出请求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.