Fetch not working in release APK
See original GitHub issue🐛 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® Core™ 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
Issue Analytics
- State:
- Created 4 years ago
- Comments:17
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.If anyone is facing the same issue, because of the “http” just add
android:usesCleartextTraffic="true"
to the Manifest, and you should be good.