bilbobaggins
bilbobaggins

Reputation: 51

React Native: Release app not connecting to local server

I'm trying to build a release version of my app on android.

Followed the necessary steps from creating a signed apk through react native docs. Once I install the apk on my device, the initial page loads but I get no response when I try to do an action calling the api.

I've ran my local server and have connected my app to the same IP with the server I'm running on.

The debug version of my app is doing well and I'm confused as to why this is happening. I'm using axios for the calls and have set my url to something like this: http://192.168.12.24:8000/api/.

Do you have ideas on what could have gone wrong? Does react native not allow using local server in a release app?

Upvotes: 1

Views: 3165

Answers (2)

Shyam Pratap Singh
Shyam Pratap Singh

Reputation: 161

Adding android:usesCleartextTraffic="true" in <application> tag in android\app\src\main\AndroidManifest.xml worked for me.

The reason is by default release build expects https url connections and it is possible that your server is having http based API like http://192.168.12.24:8000/api/, so to avoid this filter, usesCleartextTraffic="true" makes http based api to be accessible from release build.

you can read more about here. https://github.com/facebook/react-native/issues/24361

enter image description here

Upvotes: 5

bilbobaggins
bilbobaggins

Reputation: 51

I managed to fix the problem. It turns out I should run the bundle every time I generate a new apk.

This is what I did:

react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest andro id/app/src/main/res

cd android

./gradlew assembleRelease

Referenced from this answer.

Upvotes: 3

Related Questions