Allow packager server port to be configurable
I have McAfee Agent Service occupying port 8081. So I changed the port 8081 hardcoding all over react-native modules (wherever I could find) to a new open port 8888. After npm start I could see the status and bundle URLs - http://localhost:8888/status and http:localhost:8888/index.android.bundle via browser and those returned some data (seems valid). However, when I start run-android, for some reason the deployed app dies with red screen and in Android monitor I see an exception which shows it is still trying to load the bundle from port 8081 instead of 8888. I have changed every occurrence of 8081 to 8888, in my react-native npm modules as well as the generated code in my app. Does anybody know what I am missing? The only option left it seems is to decompile the apk classes and change the bytecode to hit 8888 instead of 8081.
10-26 16:22:54.298: E/unknown:React(2259): Unable to download JS bundle 10-26 16:22:54.298: E/unknown:React(2259): java.io.IOException: unexpected end of stream on Connection{10.0.2.2:8081, proxy=DIRECT@ hostAddress=10.0.2.2 cipherSuite=none protocol=http/1.1} (recycle count=0) 10-26 16:22:54.298: E/unknown:React(2259): at com.squareup.okhttp.internal.http.HttpConnection.readResponse(HttpConnection.java:211) 10-26 16:22:54.298: E/unknown:React(2259): at com.squareup.okhttp.internal.http.HttpTransport.readResponseHeaders(HttpTransport.java:80) 10-26 16:22:54.298: E/unknown:React(2259): at com.squareup.okhttp.internal.http.HttpEngine.readNetworkResponse(HttpEngine.java:917) 10-26 16:22:54.298: E/unknown:React(2259): at com.squareup.okhttp.internal.http.HttpEngine.access$300(HttpEngine.java:95) 10-26 16:22:54.298: E/unknown:React(2259): at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:902) 10-26 16:22:54.298: E/unknown:React(2259): at com.squareup.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:760) 10-26 16:22:54.298: E/unknown:React(2259): at com.squareup.okhttp.Call.getResponse(Call.java:274) 10-26 16:22:54.298: E/unknown:React(2259): at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:230) 10-26 16:22:54.298: E/unknown:React(2259): at com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:201) 10-26 16:22:54.298: E/unknown:React(2259): at com.squareup.okhttp.Call.access$100(Call.java:36) 10-26 16:22:54.298: E/unknown:React(2259): at com.squareup.okhttp.Call$AsyncCall.execute(Call.java:164) 10-26 16:22:54.298: E/unknown:React(2259): at com.squareup.okhttp.internal.NamedRunnable.run(NamedRunnable.java:33) 10-26 16:22:54.298: E/unknown:React(2259): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 10-26 16:22:54.298: E/unknown:React(2259): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 10-26 16:22:54.298: E/unknown:React(2259): at java.lang.Thread.run(Thread.java:818) 10-26 16:22:54.298: E/unknown:React(2259): Caused by: java.io.EOFException: \n not found: size=0 content=... 10-26 16:22:54.298: E/unknown:React(2259): at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:200) 10-26 16:22:54.298: E/unknown:React(2259): at com.squareup.okhttp.internal.http.HttpConnection.readResponse(HttpConnection.java:191) 10-26 16:22:54.298: E/unknown:React(2259): ... 14 more
Dupe of #1429 I think
But what is the part of Android specific code I am missing? I changed all occurences of 8081 to 8888, but still when the app is deployed in the emulator, I see the emulator tries to load the js bundle from 8081 which fails. Just not able to figure out which place I have missed.
We'd accept a PR on this
I've posted this on product pains so it would be great if you could upvote it there and show the react-native team that this is an important feature https://productpains.com/post/react-native/allow-packager-port-to-be-configurable-change-from-8081/
Closing as this is duplicate of #1429
Hello there,
I have fixed this issue by the step below: if you installed McAfee antivirus, the default port of McAfee log is 8081. You should manual change the port of your react native server
Step 1: go to
const args = parseCommandLine([{ command: 'port', default: 8088, type: 'string', }
Step 2: Create an "assets" folder under "android/app/src/main"
Step 3: in node.js run "react-native start" and navigate to the url "http://localhost:8088/index.android.bundle?platform=android"
Step 4: save the bundle to assets folder and you are all set. in node.js run "react-native run-android" to view the result
Regards,
Hai Tang
This can be resolved by the dev settings inside the emulator , please visit my site for more information,
http://gadoth.com/react-native-series-post-1-installation-setup/