skip to Main Content

My React Native Application is not getting internet on some device.
The released application was build using ./gradlew bundleRelease and then ./gradlew assembleRelease. Application is fetching data from a remote server http://hptrade.unaux.com. Application is running smoothly on devices that i use in my house (4 android devices) but other devices not getting any data using my application. All the requests are GET and post request using XMLHttpRequest

I have tried by adding this line of code to my AndroidManifest.xml

android:usesCleartextTraffic="true">

This one also didn’t helped

here is my AndroidManifest.xml file

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.nobabkhaan.hp">

    <uses-permission android:name="android.permission.INTERNET" />
    <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:roundIcon="@mipmap/ic_launcher_round"
      android:allowBackup="false"
      android:theme="@style/AppTheme"
      android:usesCleartextTraffic="true">
      <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|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>
    </application>
</manifest>

package.json

{
  "name": "HP",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "lint": "eslint .",
    "start": "react-native start",
    "test": "jest"
  },
  "dependencies": {
    "@react-native-async-storage/async-storage": "^1.18.1",
    "@react-native-masked-view/masked-view": "^0.2.9",
    "@react-navigation/bottom-tabs": "^6.5.7",
    "@react-navigation/drawer": "^6.6.2",
    "@react-navigation/native": "^6.1.6",
    "@react-navigation/native-stack": "^6.9.12",
    "@react-navigation/stack": "^6.3.16",
    "axios": "^1.4.0",
    "react": "18.2.0",
    "react-native": "^0.71.8",
    "react-native-compressor": "^1.6.1",
    "react-native-device-info": "^10.6.0",
    "react-native-dropdown-picker": "^5.4.6",
    "react-native-gesture-handler": "^2.10.1",
    "react-native-image-picker": "^5.4.0",
    "react-native-linear-gradient": "^2.6.2",
    "react-native-reanimated": "^3.1.0",
    "react-native-safe-area-context": "^4.5.3",
    "react-native-screens": "^3.20.0",
    "react-native-splash-screen": "^3.3.0",
    "react-native-vector-icons": "^9.2.0",
    "react-navigation": "^4.4.4"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0",
    "@babel/preset-env": "^7.20.0",
    "@babel/runtime": "^7.20.0",
    "@react-native-community/eslint-config": "^3.2.0",
    "@tsconfig/react-native": "^2.0.2",
    "@types/jest": "^29.2.1",
    "@types/react": "^18.0.24",
    "@types/react-test-renderer": "^18.0.0",
    "babel-jest": "^29.2.1",
    "eslint": "^8.19.0",
    "jest": "^29.2.1",
    "metro-react-native-babel-preset": "0.73.9",
    "prettier": "^2.4.1",
    "react-test-renderer": "18.2.0",
    "typescript": "4.8.4"
  },
  "jest": {
    "preset": "react-native"
  }
}

If someone help me out I would be greatful.

2

Answers


  1. Chosen as BEST ANSWER

    Finally, I solved the problem. The problem was I was using HTTP But by default react components blocked HTTP. So I had to switch to HTTPS for APIs.


  2. Instead of using Axios Try fetch

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search