I am developing an app using Expo, and I’m fetching data from a local API endpoint (http://192.168.110.13:5878) within my LAN. The app works perfectly in the development environment (using expo start), and I can see the data being fetched from the API. However, after building the APK using eas build --platform android, the app fails to fetch data from the same API endpoint.
Here are the key points:
Development Mode :The API call works fine when running the app in development mode.The API is hosted on a local server within the LAN, and the device/emulator can access it.Production APK :After building the APK, the app does not fetch data from the API.No errors are visible in the app UI, but logging shows that the API call fails.API Endpoint :The API uses HTTP (not HTTPS) and is accessible only within the local network.Example URL: http://192.168.110.13:5878/bdno_from_mcno?mcno=123.
const fetchBreakDownNum = async () => { if (!machineNo) return; setLoading(true); try { const apiURL = `http://192.168.110.13:5878/bdno_from_mcno?mcno=${machineNo}`; console.log("Fetching breakdown numbers", apiURL); const response = await axios.get(apiURL, { headers: { "Content-Type": "application/json" }, }); if (Array.isArray(response.data)) { console.log("Fetched breakdown numbers:", response.data); setBreakdownNumber(response.data); } else { console.error("Unexpected response format:", response.data); setBreakdownNumber([]); } } catch (error) { console.error("Error fetching breakdown data:", error.message); Alert.alert("Error", "Failed to fetch data. Please check your connection."); setBreakdownNumber([]); } finally { setLoading(false); } }; fetchBreakDownNum();}, [machineNo]);Expo configuration
{"expo": {"name": "BreakDown Closure","slug": "CrudApp","version": "1.0.0","orientation": "portrait","icon": "./assets/images/tvss_logo.jpg","scheme": "myapp","userInterfaceStyle": "automatic","newArchEnabled": true,"ios": {"supportsTablet": true,"bundleIdentifier": "com.jasmine3.CrudApp" },"android": {"adaptiveIcon": {"foregroundImage": "./assets/images/tvss_logo.jpg","backgroundColor": "#ffffff" },"permissions": ["android.permission.CAMERA","android.permission.INTERNET","android.permission.ACCESS_NETWORK_STATE","android.permission.ACCESS_WIFI_STATE" ],"usesCleartextTraffic": true,"package": "com.jasmine3.CrudApp" },"web": {"bundler": "metro","output": "static","favicon": "./assets/images/favicon.png" } }}Steps Taken So FarEnabled "usesCleartextTraffic": true in app.json.Verified that the API is accessible from the browser on the same network.Rebuilt the APK multiple times using eas build --platform android.Tested on a physical device connected to the same Wi-Fi network as the server.
Expected Behavior :The app should fetch data from the local API in both development and production modes.
Actual Behavior :The API call works in development mode but fails in the production APK.