facebook / react-native

A framework for building native applications using React
https://reactnative.dev
MIT License
118.78k stars 24.29k forks source link

Websocket is not working in android release apk, while working fine in development mode 0.71.6 #36922

Closed learncodingforweb closed 1 year ago

learncodingforweb commented 1 year ago

Description

websocket is working fine in development mode for android. using yarn start yarn android

If try to create android apk relase using 1) cd android 2) ./gradlew assembleRelease

It is not working

React Native Version

0.71.6

Output of npx react-native info

info Fetching system and libraries information... System: OS: Linux 5.19 Ubuntu 22.04.2 LTS 22.04.2 LTS (Jammy Jellyfish) CPU: (4) x64 Intel(R) Core(TM) i3-8100T CPU @ 3.10GHz Memory: 1.65 GB / 7.47 GB Shell: 5.1.16 - /bin/bash Binaries: Node: 18.12.1 - ~/.nvm/versions/node/v18.12.1/bin/node Yarn: 1.22.19 - ~/.nvm/versions/node/v18.12.1/bin/yarn npm: 8.19.2 - ~/.nvm/versions/node/v18.12.1/bin/npm Watchman: 20230222.123454.0 - /usr/local/bin/watchman SDKs: Android SDK: API Levels: 32, 33, 33 Build Tools: 30.0.3, 33.0.0, 33.0.2 Android NDK: Not Found IDEs: Android Studio: Not Found Languages: Java: 18.0.2-ea - /usr/bin/javac npmPackages: @react-native-community/cli: Not Found react: 18.2.0 => 18.2.0 react-native: 0.71.6 => 0.71.6 npmGlobalPackages: react-native: Not Found

Steps to reproduce

1) create react app using npx react-native init myapp 2) checkout repo code on websocket_android 3) cd android 4) ./gradlew assembleRelease I am getting warnings messages on console

Task :app:createBundleReleaseJsAndAssets warning: the transform cache was reset. Welcome to Metro v0.73.9 Fast - Scalable - Integrated

info Writing bundle output to:, /home/myname/dev/concept/myapp/android/app/build/ASSETS/createBundleReleaseJsAndAssets/index.android.bundle info Writing sourcemap output to:, /home/myname/dev/concept/myapp/android/app/build/intermediates/sourcemaps/react/release/index.android.bundle.packager.map info Done writing bundle output info Done writing sourcemap output /home/myname/dev/concept/myapp/android/app/build/ASSETS/createBundleReleaseJsAndAssets/index.android.bundle:1713:23: warning: the variable "DebuggerInternal" was not declared in function "shouldPauseOnThrow" return typeof DebuggerInternal !== 'undefined' && DebuggerInternal.shouldPauseOnThrow === true; ^~~~ /home/myname/dev/concept/myapp/android/app/build/ASSETS/createBundleReleaseJsAndAssets/index.android.bundle:4933:7: warning: the variable "setTimeout" was not declared in function "logCapturedError" setTimeout(function () { ^~~~~~ /home/myname/dev/concept/myapp/android/app/build/ASSETS/createBundleReleaseJsAndAssets/index.android.bundle:2907:108: warning: the variable "nativeFabricUIManager" was not declared in function "onChange" (fromOrTo = fromOrTo && fromOrTo.stateNode) && fromOrTo.canonical.internalInstanceHandle ? (from && nativeFabricUIManager.setIsJSResponder(from.stateNode.node, false, blockNativeResponder || false), to && nativeFabricUIManager.setIsJSResponder(to.stateNode.node, true, blockNativeResponder || false)) : null !== to ? $$_REQUIRE(_dependencyMap[2]).UIManager.setJSResponder(to.stateNode.canonical.nativeTag, blockNativeResponder) : $$_REQUIRE(_dependencyMap[2]).UIManager.clearJSResponder(); ^~~~~ /home/myname/dev/concept/myapp/android/app/build/ASSETS/createBundleReleaseJsAndAssets/index.android.bundle:3514:21: warning: the variable "clearTimeout" was not declared in anonymous function " 98#" cancelTimeout = clearTimeout; ^~~~ /home/myname/dev/concept/myapp/android/app/build/ASSETS/createBundleReleaseJsAndAssets/index.android.bundle:7264:30: warning: the variable "REACT_DEVTOOLS_GLOBAL_HOOK" was not declared in anonymous function " 98#" if ("undefined" !== typeof REACT_DEVTOOLS_GLOBAL_HOOK__) { ^~~~~~~~~~ /home/myname/dev/concept/myapp/android/app/build/ASSETS/createBundleReleaseJsAndAssets/index.android.bundle:8033:5: warning: the variable "setImmediate" was not declared in function "handleResolved" setImmediate(function () { ^~~~ /home/myname/dev/concept/myapp/android/app/build/ASSETS/createBundleReleaseJsAndAssets/index.android.bundle:8244:16: warning: the variable "AggregateError" was not declared in function "getAggregateError" if (typeof AggregateError === 'function') { ^~~~~~ /home/myname/dev/concept/myapp/android/app/build/ASSETS/createBundleReleaseJsAndAssets/index.android.bundle:10993:12: warning: the variable "fetch" was not declared in anonymous function " 301#" fetch: fetch, ^~~~~ /home/myname/dev/concept/myapp/android/app/build/ASSETS/createBundleReleaseJsAndAssets/index.android.bundle:10994:14: warning: the variable "Headers" was not declared in anonymous function " 301#" Headers: Headers, ^~~ /home/myname/dev/concept/myapp/android/app/build/ASSETS/createBundleReleaseJsAndAssets/index.android.bundle:10995:14: warning: the variable "Request" was not declared in anonymous function " 301#" Request: Request, ^~~ /home/myname/dev/concept/myapp/android/app/build/ASSETS/createBundleReleaseJsAndAssets/index.android.bundle:10996:15: warning: the variable "Response" was not declared in anonymous function " 301#" Response: Response ^~~~ /home/myname/dev/concept/myapp/android/app/build/ASSETS/createBundleReleaseJsAndAssets/index.android.bundle:11144:24: warning: the variable "FileReader" was not declared in function "readBlobAsArrayBuffer" var reader = new FileReader(); ^~~~~~ /home/myname/dev/concept/myapp/android/app/build/ASSETS/createBundleReleaseJsAndAssets/index.android.bundle:11181:36: warning: the variable "Blob" was not declared in anonymous function " 312#" } else if (support.blob && Blob.prototype.isPrototypeOf(body)) { ^~~~ /home/myname/dev/concept/myapp/android/app/build/ASSETS/createBundleReleaseJsAndAssets/index.android.bundle:11183:40: warning: the variable "FormData" was not declared in anonymous function " 312#" } else if (support.formData && FormData.prototype.isPrototypeOf(body)) { ^~~~ /home/myname/dev/concept/myapp/android/app/build/ASSETS/createBundleReleaseJsAndAssets/index.android.bundle:11185:44: warning: the variable "URLSearchParams" was not declared in anonymous function " 312#" } else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) { ^~~~~~~ /home/myname/dev/concept/myapp/android/app/build/ASSETS/createBundleReleaseJsAndAssets/index.android.bundle:11412:23: warning: the variable "XMLHttpRequest" was not declared in anonymous function " 321#" var xhr = new XMLHttpRequest(); ^~~~~~ /home/myname/dev/concept/myapp/android/app/build/ASSETS/createBundleReleaseJsAndAssets/index.android.bundle:11005:76: warning: the variable "self" was not declared in anonymous function " 304#" var global = typeof globalThis !== 'undefined' && globalThis || typeof self !== 'undefined' && self || typeof global !== 'undefined' && global; ^~~~ /home/myname/dev/concept/myapp/android/app/build/ASSETS/createBundleReleaseJsAndAssets/index.android.bundle:16644:27: warning: the variable "performance" was not declared in anonymous function " 560#" if ("object" === typeof performance && "function" === typeof performance.now) { ^~~ /home/myname/dev/concept/myapp/android/app/build/ASSETS/createBundleReleaseJsAndAssets/index.android.bundle:16667:26: warning: the variable "navigator" was not declared in anonymous function " 560#" "undefined" !== typeof navigator && undefined !== navigator.scheduling && undefined !== navigator.scheduling.isInputPending && navigator.scheduling.isInputPending.bind(navigator.scheduling); ^~~~~ /home/myname/dev/concept/myapp/android/app/build/ASSETS/createBundleReleaseJsAndAssets/index.android.bundle:16734:37: warning: the variable "MessageChannel" was not declared in anonymous function " 560#" };else if ("undefined" !== typeof MessageChannel) { ^~~~~~ /home/myname/dev/concept/myapp/android/app/build/ASSETS/createBundleReleaseJsAndAssets/index.android.bundle:24933:34: warning: the variable "requestAnimationFrame" was not declared in function "start 9#" this._animationFrame = requestAnimationFrame(this.onUpdate.bind(this)); ^~~~~

BUILD SUCCESSFUL in 35s 47 actionable tasks: 42 executed, 5 up-to-date

5) Install apk under android/app/build/outputs/apk/release/app-release.apk

Websocket is not working.

Snack, code example, screenshot, or link to a repository

example code available at https://github.com/learncodingforweb/websocket_android.git

hichemfantar commented 1 year ago

Have you checked for CORS errors? Please provide a snippet of the error when trying to connect.

blakef commented 1 year ago

Looking at your code, this doesn't look like a react-native issue (all the warning pasted are a red herring).

From a quick look of your code, you're using ws instead of wss.

  1. Try see what error message is being returned by your client, and
  2. look here if it's related to platform restrictions on clear text communication for a way around.
github-actions[bot] commented 1 year ago

This issue is waiting for author's feedback since 24 days. Please provide the requested feedback or this will be closed in 7 days.

yang1212 commented 1 year ago

Encountering the same error, I looked at my project request address prefix is also ws://, and then changed the request address prefix from ws:// to wss:// package apk again.

onderbakirtas commented 1 year ago

This output happens with bare minimum React Native project, just bootstrapped one with the command that is on RN website. I just installed installed react-native-bootsplash and followed their guide for Android.

github-actions[bot] commented 1 year ago

This issue is waiting for author's feedback since 24 days. Please provide the requested feedback or this will be closed in 7 days.

github-actions[bot] commented 1 year ago

This issue was closed because the author hasn't provided the requested feedback after 7 days.

sebas21 commented 1 year ago

does this have a solution?

tunm1228 commented 1 year ago

You try Clean Project and Rebuild