React native fetch/axios api calls always goes to catch - api

I have tried using both fetch and axios. But both of these calls fail in my react-native application. It always goes into the catch function. Though calling this api from the browser or from Postman works fine.
axios.get('http://sahajdevapi.letsendorse.com')
.then(function (response) {
console.warn("res 1: ", response);
}).catch(function (error) {
console.warn("err 1: ", error);
});
The error that I get from the catch function is as follows:
'err:', { [TypeError: Network request failed]
line: 24115,
column: 31,
sourceURL: 'http://localhost:8081/index.delta?platform=android&dev=true&minify=false'}

For newer version you need to add some security for http access.
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<application
android:name=".MainApplication"
android:allowBackup="false"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#drawable/ic_launcher_round"
android:theme="#style/AppTheme"
android:usesCleartextTraffic="true"
tools:ignore="GoogleAppIndexingWarning">
<uses-library
android:name="org.apache.http.legacy"
android:required="false" />
<activity
android:name=".MainActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:label="#string/app_name"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>
</manifest>
Check your file you need to add in manifest tag tools and uses-library for that.
Try this one it will work.

As android VM is an emulator If we use localhost then its points to local host of the android emulator system but not localhost of the development system. So use system IP address instead of localhost

Related

While releasing react native app to the play store getting error, This file can't be installed on Android 12 or higher

You uploaded an APK or Android App Bundle which has an activity, activity alias, service or broadcast receiver with intent filter, but without the 'android:exported' property set. This file can't be installed on Android 12 or higher. See: developer.android.com/about/versions/12/behavior-changes-12#
I have added the property 'android:exported' to the AndroidManifest.xml. But the same issue occurs while uploading
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.domain.example">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<application android:name=".MainApplication" android:label="#string/app_name" android:usesCleartextTraffic="true" android:icon="#mipmap/ic_launcher" android:allowBackup="false" android:theme="#style/AppTheme"
android:exported="true">
<activity android:name=".MainActivity" android:label="#string/app_name" android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode" android:launchMode="singleTask" android:windowSoftInputMode="adjustResize" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- You will also only need to add this uses-library tag -->
<uses-library android:name="org.apache.http.legacy" android:required="false" />
</application>
</manifest>

React Native firebase dynamic link, deep linking [Android]

I am using dynamic link in React Native, I have all the steps required for IOS and android setup. (dynamic link opens the app on both platform) but when I have deep link attached to it, on Android app is opened but deep link parameters are not passed.
IOS works fine, deep link works correctly.
"react-native": "0.67.4",
"#react-native-firebase/app": "12.7.4",
"#react-native-firebase/dynamic-links": "12.7.4",
device: Xiaomi mi 9,
browser: Xiaomi browser,
deeplink: https://sweeftdigital.page.link/transfer_tip?userId=3
deep link debug version
video
Press to see video
In this video there are two browser: Mi browser and chrome browser,
Mi browser: when pressing dynamic link, it opens app directly without passing parameters.
chrome: when pressing dynamic link, it asks to open either in browser or open app, when you choose and app it passes parameters and deep link works.
AndroidManifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tipapp">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-feature android:name="android.hardware.camera" android:required="false" />
<uses-feature android:name="android.hardware.camera.front" android:required="false" />
<application android:name=".MainApplication"
android:label="#string/app_name"
android:icon="#mipmap/ic_launcher"
android:allowBackup="false"
android:usesCleartextTraffic="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity"
android:exported='true'
android:label="#string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize">
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.DOWNLOAD_COMPLETE" />
</intent-filter>
<intent-filter >
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- Accepts URIs that begin with "https://www.sweeftdigital.page.link/” -->
<data android:scheme="https"
android:host="sweeftdigital.page.link" />
<!-- Accepts URIs that begin with "tipapp://” -->
<data android:scheme="tipapp" />
</intent-filter>
</activity>
</application>
</manifest>
deep link handling with react navigation
const config = {
screens: {
webView: {
path: '/transfer_tip',
parse: {
userId: (userId: any) => userId,
},
},
authLoading: '*',
},
};
const linking = {
prefixes: ['tipapp://', 'https://sweeftdigital.page.link'],
config: config,
};
<NavigationContainer
linking={linking}
...
Is there anything incorrect or is it firebase dynamic links normal behaviour?

React-Native: Crashes on android when using openCamera using react-native-image-crop-picker and Camera in general

I've been having issues with react-native-image-picker and react-native-image-crop-picker while opening camera on my One Plus 6 for a while now.
While using opening the camera, the background app that opened the camera (my app) crashes. It goes to a white screen and the restarts the app.
Moreover, there were no logs in react-native log-android.
I did manage to find out using android studio and logcat that once the camera opens the app crashes straight away and leaves a dead process.
The issues is that I can't find any actual logs of the crash.
Although beforehand I'm getting a lot of "Access denied finding property "vendor.debug.egl.swapinterval"" which after some research doesn't seem related.
This issues as of right now happens only on my One Plus 6T. The issues doesn't occur on an emulator or on IOS. Even not on a xiamoi device I tried it on.
I've tried everything from compressing the images in image crop picker (Code number one), and trying compress the image and using the noData flag in react-native-image-picker (code number two).
Also, 100% have permissions, even can see it in permissions of android system in App permmision => {my app}
Moreover, I tried cleaning the cache of my One Plus 6t camera, uninstalled-reinstalled my app, and reseting developer options to default.
I've basically went through all issues in github for both libraries and nothing works.
ImagePicker.openCamera({
width: 800,
height: 600,
compressImageMaxWidth: 640,
compressImageMaxHeight: 480,
compressImageQuality: 0.8
}).then(image => {
console.log(image);
}).catch(e => console.log(e));
ImagePicker.launchCamera({noData: true, maxWidth: 800, maxHeight: 600, quality: 0.8}, (response) => {
console.log('Response = ', response);
if (response.didCancel) {
console.log('User cancelled image picker');
} else if (response.error) {
console.log('ImagePicker Error: ', response.error);
} else if (response.customButton) {
console.log('User tapped custom button: ', response.customButton);
} else {
console.log(response)
}
});
Adding my manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="------">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-feature android:name="android.hardware.camera" android:required="false"/>
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false"/>
<uses-feature android:name="android.hardware.camera.front" android:required="false" />
<application
android:name=".MainApplication"
android:label="#string/app_name"
android:largeHeap="true"
android:icon="#mipmap/ic_launcher"
android:roundIcon="#mipmap/ic_launcher_round"
android:allowBackup="true"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize"
android:launchMode="singleTop"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
<service android:name="io.invertase.firebase.messaging.RNFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service android:name="io.invertase.firebase.messaging.RNFirebaseInstanceIdService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.provider" android:exported="false"
android:grantUriPermissions="true"> <meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/provider_paths" /> </provider>
</application>
</manifest>
expected result is to get the promise back. and the app not to crash when opening the camera.
Would love to get some input. I'm having this issue more then 2 weeks now.
I made it work by updating OxygenOS from 9.0.4 to 9.0.5.
I had exactly the same issue, trying both react-native-image-picker and react-native-image-crop-picker. It worked fine on the Android and iOS simulators but not on the device, a One Plus 6. But things started to click when it worked on a coworker's identical phone!
Make sure you try the release build. In my case I had to add some ProGuard rules for native-image-crop-picker from https://github.com/Yalantis/uCrop
Copy this
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.provider" android:exported="false"
android:grantUriPermissions="true"> <meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/provider_paths" /> </provider>
into your main project android manifest.

Android: react-native-image-picker manifest.xml invalid file path

Sorry if i don't fully respect the question pattern, it is my first question on StackOverflow. :)
I am trying to run my react native app on Android (for the first time) after a long period of code (I was only testing on iOS).
I have been fixing a lot of issues mentioned by Android Studio but can't figure out the following one:
error: invalid file path 'my_path/node_modules/react-native-image-picker/android/build/intermediates/manifests/aapt/release/AndroidManifest.xml'.
My config:
"react-native-image-picker": "^0.27.2"
"react-native": "0.56.0"
I have followed the path mentioned above, and the file exist and doesn't seem to have any error in it.
I also followed the install doc from react-native-image-picker
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application
android:name=".MainApplication"
android:label="#string/app_name"
android:icon="#mipmap/ic_launcher"
android:allowBackup="false"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>
Please do below steps to resolve.
File > Invalidate Caches/Restart

react-native run-android Cannot read packageName

I using this code react-native run-android It gives this error
Cannot read packageName from D:\projects\test3\android\src\main\AndroidManifest.xml
when I update my Gradle version to 2.2
this is my manifest file code:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test3">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<application
android:name=".MainApplication"
android:label="#string/app_name"
android:icon="#mipmap/ic_launcher"
android:allowBackup="false"
android:theme="#style/AppTheme">
<service android:name=".HeadlessTaskService"
android:enabled="true" />
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>
</manifest>
1.make sure your device is connected and you had enabled debugging mode in it.
2.set paths for android_home,tools and platform_tools
3.then on console run,
adb reverse tcp:8081 tcp:8081
this command runs properly on android devices having version greater than 4.4
4.then try
react-native run-android