react-native
react-native copied to clipboard
Websocket is not working in android release apk, while working fine in development mode 0.71.6
Description
websocket is working fine in development mode for android. using yarn start yarn android
If try to create android apk relase using
- cd android
- ./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
- create react app using npx react-native init myapp
- checkout repo code on websocket_android
- cd android
- ./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
- 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
Have you checked for CORS errors? Please provide a snippet of the error when trying to connect.
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
.
- Try see what error message is being returned by your client, and
- look here if it's related to platform restrictions on clear text communication for a way around.
This issue is waiting for author's feedback since 24 days. Please provide the requested feedback or this will be closed in 7 days.
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.
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.
This issue is waiting for author's feedback since 24 days. Please provide the requested feedback or this will be closed in 7 days.
This issue was closed because the author hasn't provided the requested feedback after 7 days.
does this have a solution?
You try Clean Project and Rebuild