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
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"
});
})
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
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.
Make sure your
config.urlServeris 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
Make sure your
config.urlServeris 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.
If anyone is facing the same issue, because of the "http" just add android:usesCleartextTraffic="true" to the Manifest, and you should be good.
adding android:usesCleartextTraffic="true" solved my problem , I was facing issues when making Http requests .
I have android:usesCleartextTraffic="true" set, but still having the same issue.
@eric-khoury 瑙e喅浜嗗悧
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
hmm using react-native 60.5 and I have this issue in release build ....
@schumannd can you tell me what did you do with the react-native-config package to solve the problem? Thank you very much
@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.
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 鈽癸笍
@rodrigomf24 we ended up running into several other issues with this package as well. I would open an issue over at their repo
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.
Adding android:usesCleartextTraffic="true" in <application> tag in android\app\src\main\AndroidManifest.xml worked for me.
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!
same error here, i put android:usesCleartextTraffic="true" and use HTTPS. GET and POST work, but PUT don't. Why?
Most helpful comment
Make sure your
config.urlServeris not an HTTP endpoint but should be HTTPS. Latest RN versions target recent Android SDK that blocks insecure HTTP connections automatically.