Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch not working in release APK #24361

Closed
jessk77 opened this issue Apr 8, 2019 · 17 comments
Closed

Fetch not working in release APK #24361

jessk77 opened this issue Apr 8, 2019 · 17 comments
Labels
Bug 🌐Networking Related to a networking API. Resolution: Locked This issue was locked by the bot.

Comments

@jessk77
Copy link

jessk77 commented Apr 8, 2019

🐛 Bug Report

I use a login in my app, when I test on development environment on my phone I have any trouble I can log in. But when I build the release APK it seems like the app can not connect with the fetch (the code enter in the catch of the fetch)
My AndroidMainfest.xml has the INTERNET pemission

Code Example

fetch(config.urlServer + "/index.php/AppServer/signin", { method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', }, body: JSON.stringify({ email: this.state.email, password: this.state.password }) }).then(res => res.json()) .then((responseJson) => { console.log(responseJson); if(responseJson.result){ this.props.setSession(responseJson.user); this.props.navigation.navigate('Main'); }else{ Toast.show({ text: responseJson.error, buttonText: 'Cerrar', type: "danger" }); } }).catch((error) => { console.error(error); Toast.show({ text: 'Hubo un Error', buttonText: 'Cerrar', type: "danger" }); })

Environment

React Native Environment Info:
System:
OS: macOS 10.14
CPU: (4) x64 Intel(R) Core(TM) i5-5350U CPU @ 1.80GHz
Memory: 72.54 MB / 8.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 10.9.0 - /usr/local/bin/node
Yarn: 1.9.4 - /usr/local/bin/yarn
npm: 6.4.1 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1
Android SDK:
API Levels: 19, 23, 24, 26, 27, 28
Build Tools: 23.0.1, 26.0.3, 27.0.3, 28.0.2, 28.0.3
IDEs:
Xcode: 10.1/10B61 - /usr/bin/xcodebuild
npmPackages:
react: 16.8.3 => 16.8.3
react-native: 0.59.3 => 0.59.3
npmGlobalPackages:
create-react-native-app: 1.0.0
react-native-cli: 2.0.1
react-native-rename: 2.4.1

@react-native-bot react-native-bot added the 🌐Networking Related to a networking API. label Apr 8, 2019
@hey99xx
Copy link

hey99xx commented Apr 8, 2019

Make sure your config.urlServer is not an HTTP endpoint but should be HTTPS. Latest RN versions target recent Android SDK that blocks insecure HTTP connections automatically.

@jessk77
Copy link
Author

jessk77 commented Apr 9, 2019

Make sure your config.urlServer is not an HTTP endpoint but should be HTTPS. Latest RN versions target recent Android SDK that blocks insecure HTTP connections automatically.

Thanks!! I didn't know that

@nirajniroula
Copy link

Make sure your config.urlServer is not an HTTP endpoint but should be HTTPS. Latest RN versions target recent Android SDK that blocks insecure HTTP connections automatically.

Are there any documents by RN related to this change log? Please do share if it exists. And here(#24408) is a workaround for the issue.

@gabrielrra
Copy link

If anyone is facing the same issue, because of the "http" just add android:usesCleartextTraffic="true" to the Manifest, and you should be good.

@ramanasak
Copy link

adding android:usesCleartextTraffic="true" solved my problem , I was facing issues when making Http requests .

@eric-khoury
Copy link

eric-khoury commented Sep 17, 2019

I have android:usesCleartextTraffic="true" set, but still having the same issue.

@songxiaoliang
Copy link

@eric-khoury 解决了吗

@schumannd
Copy link

schumannd commented Oct 1, 2019

We are facing this issue even though all our URLs use HTTPS. Anybody else experiencing that problem?

Edit: In the end it was another package being broken that caused this: react-native-config

@Ashkan-Oliaie
Copy link

hmm using react-native 60.5 and I have this issue in release build ....

@nghiep9523
Copy link

@schumannd can you tell me what did you do with the react-native-config package to solve the problem? Thank you very much

@schumannd
Copy link

schumannd commented Oct 25, 2019

@nghiep9523 it was an issue described in their repos README under troubleshooting as "Problems with Proguard"


add an exception to android/app/proguard-rules.pro:

 -keep class com.mypackage.BuildConfig { *; }

com.mypackage should match the package value in your app/src/main/AndroidManifest.xml file.

@rodrigomf24
Copy link

Is there any fix for this? I am having the same issues with an HTTPS url, I tried @schumannd's recommendation but that didn't fixed the problem. Any help would be greatly appreciated, at this point I'm considering switching to axios ☹️

@schumannd
Copy link

@rodrigomf24 we ended up running into several other issues with this package as well. I would open an issue over at their repo

@cjahfar1
Copy link

Is there any fix for this? I am having the same issues with an HTTPS url, I tried @schumannd's recommendation but that didn't fixed the problem. Any help would be greatly appreciated, at this point I'm considering switching to axios

I am facing same issue in rn 61.5. Both http and HTTPS not working in release mode. Already tried with fetch and axios, still no difference.

@hamzawaleed0102
Copy link

Adding android:usesCleartextTraffic="true" in <application> tag in android\app\src\main\AndroidManifest.xml worked for me.

@deepas96
Copy link

My shopify public api (https://{apikey}:{password}:@{shop-domain}//admin/customers) working perfectly on ios and postman but not on android. It gives 401 error : "Invalid API key or access token (unrecognized login or wrong password)" on android phone. Any help would be greatly appreciated!

@pedroSoaresll
Copy link

same error here, i put android:usesCleartextTraffic="true" and use HTTPS. GET and POST work, but PUT don't. Why?

@facebook facebook locked as resolved and limited conversation to collaborators Apr 9, 2020
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Apr 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug 🌐Networking Related to a networking API. Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests