Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch in android not working #60

Open
shakib-rahimi opened this issue Oct 20, 2023 · 14 comments
Open

Fetch in android not working #60

shakib-rahimi opened this issue Oct 20, 2023 · 14 comments
Assignees
Labels
bug Something isn't working

Comments

@shakib-rahimi
Copy link

shakib-rahimi commented Oct 20, 2023

Hello,

I spent about two days on version 1.0.5 to fix the call to the fetch function in the event listener that was getting an error and the error was empty.

Hopefully the not LTS version 1.0.6-devxxxxx6000.0 works. I would like to raise the issue and ask: When will the LTS version for that fix come?

and the android-jw-engine-release.aar should be manually copied to android/libs/...

Greetings and thank you for this useful plugin ;)

@mahen23
Copy link

mahen23 commented Oct 20, 2023

Having issues with fetch() too under Android. Testing under Android Studio, the logcat shows that the execution proceeds inside the addEventListener but Fetch is not executing. Does not matter if I use fetch() or pure XMLHTTPREQUEST. Neither works.

@theproducer
Copy link
Collaborator

Hello @mahen23, @shakib-rahimi! Is this happening while in the background, or also when you call your function via dispatchEvent?

@petrot
Copy link

petrot commented Oct 24, 2023

Same error here... @theproducer it's happening with the demo code for me.

@theproducer theproducer added the bug Something isn't working label Oct 24, 2023
@theproducer theproducer self-assigned this Oct 24, 2023
@shakib-rahimi
Copy link
Author

shakib-rahimi commented Oct 24, 2023

Hi @theproducer, it's happening in the runner.js after calling it from dispatchEvent, i ran it with try...catch, and after catching the error was empty.

these are my package versions:

"dependencies": {
"@angular/animations": "^16.0.0",
"@angular/common": "^16.0.0",
"@angular/compiler": "^16.0.0",
"@angular/core": "^16.0.0",
"@angular/forms": "^16.0.0",
"@angular/platform-browser": "^16.0.0",
"@angular/platform-browser-dynamic": "^16.0.0",
"@angular/router": "^16.0.0",
"@capacitor/android": "5.5.0",
"@capacitor/app": "5.0.6",
"@capacitor/background-runner": "^1.0.5",
"@capacitor/core": "5.5.0",
"@capacitor/haptics": "5.0.6",
"@capacitor/ios": "5.5.0",
"@capacitor/keyboard": "5.0.6",
"@capacitor/status-bar": "5.0.6",
"@ionic/angular": "^7.0.0",
"ionicons": "^7.0.0",
"rxjs": "~7.8.0",
"tslib": "^2.3.0",
"zone.js": "~0.13.0"
},
"devDependencies": {
"@angular-devkit/build-angular": "^16.0.0",
"@angular-eslint/builder": "^16.0.0",
"@angular-eslint/eslint-plugin": "^16.0.0",
"@angular-eslint/eslint-plugin-template": "^16.0.0",
"@angular-eslint/schematics": "^16.0.0",
"@angular-eslint/template-parser": "^16.0.0",
"@angular/cli": "^16.0.0",
"@angular/compiler-cli": "^16.0.0",
"@angular/language-service": "^16.0.0",
"@capacitor/cli": "5.5.0",
"@ionic/angular-toolkit": "^9.0.0",
"@types/jasmine": "~4.3.0",
"@types/node": "^12.11.1",
"@typescript-eslint/eslint-plugin": "5.3.0",
"@typescript-eslint/parser": "5.3.0",
"eslint": "^7.26.0",
"eslint-plugin-import": "2.22.1",
"eslint-plugin-jsdoc": "30.7.6",
"eslint-plugin-prefer-arrow": "1.2.2",
"jasmine-core": "~4.6.0",
"jasmine-spec-reporter": "~5.0.0",
"karma": "~6.4.0",
"karma-chrome-launcher": "~3.2.0",
"karma-coverage": "~2.2.0",
"karma-coverage-istanbul-reporter": "~3.0.2",
"karma-jasmine": "~5.1.0",
"karma-jasmine-html-reporter": "~2.0.0",
"ts-node": "^8.3.0",
"typescript": "~5.0.2"
},

And ng version output:

Angular CLI: 16.2.6
Node: 18.17.0
Package Manager: npm 9.8.1
OS: darwin arm64

Angular: 16.2.9
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package Version

@angular-devkit/architect 0.1602.6
@angular-devkit/build-angular 16.2.6
@angular-devkit/core 16.2.6
@angular-devkit/schematics 16.2.6
@angular/cli 16.2.6
@schematics/angular 16.2.6
rxjs 7.8.1
typescript 5.0.4
zone.js 0.13.3

@Burzo
Copy link

Burzo commented Oct 26, 2023

@theproducer I'm also having this issue. Unfortunately, I was testing this library a few weeks ago, so I can't give you the details, but something is definitely wrong. If you have trouble reproducing it, I can recreate an example for you, just let me know.

@theproducer
Copy link
Collaborator

Thanks, I suspect it may have to do with the way we are bundling the .aar for the Android JS Engine. I'm working on a fix now, stay tuned!

@sburghgraeve
Copy link

Hi,
I do meet the same problem as it seems, latest version of ionic + capacitor + vue.
When doing the fetch, thread freeze and spike in cpu usage.

iawared: fg_hl_ctl check high load task, tid:12439, threadName:Thread-8, packageName:com.xxxxxxxx.app, percent:99 doCtrl=1

If any I can also try to give you a use case.

@Burzo
Copy link

Burzo commented Nov 23, 2023

Hey @theproducer sorry to bother you with this, but how is the fix for this going? This is blocking us from actually using the plugin in production.

Thank you for all the work so far.

@stellar-security-os
Copy link

Is there any updates on this? We tried to use latest version of the plugin, fetch does not work.

@steve-m4b
Copy link

@theproducer did you make any progress on the fix, I did try to use the 1.0.6 (snapshot) but with no success.
Also start to look at your code in case I can start contributing, but I still need to figure the overall capacitor logic and how to test, it it will take a bit of time :-(

@louis123562
Copy link

We have the same issue - on iOS, fetching (GET,POST) works great, but on android it does not work at all :(

@giulia3ferri
Copy link

I have the same problem in android. The error is empty and there are no fetching results.

@PratikBodawala
Copy link
Contributor

PratikBodawala commented Aug 25, 2024

I have a similar issue,
Here is my snippet,

const resp = await fetch(
    'https://backend.ngrok-free.app/api/location/location',
    {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: '{"foo": "bar"}',
    },
  )

it is sending data like this, appending 1 or 2 hex chars before JSON and 0 after JSON.

Host: backend.ngrok-free.app
User-Agent: Dalvik/2.1.0 (Linux; U; Android 14)
Transfer-Encoding: chunked
Accept-Encoding: gzip
Content-Type: application/json
Cookie: sessionid=72g7136808dfqwrudc4ym6a471mxoh
X-Forwarded-For: xx.xx.xx.xx
X-Forwarded-Host: backend.ngrok-free.app
X-Forwarded-Proto: https

e
{"foo": "bar"}
0

background-runner version: 1.1.0

how to send post request without being chunked?
I have tried adding content-length by manually adding it to the header, but did not work.

@PratikBodawala
Copy link
Contributor

PratikBodawala commented Aug 26, 2024

Hi everyone,

I’ve resolved the fetch issue for my use case and have opened a separate issue along with PR #105. Please review it once the PR is merged. If your use case is still not resolved, kindly share a code snippet to reproduce the issue, and I’ll do my best to address it.

Additionally, if you find my PR helpful, feel free to support me by sponsoring through my GitHub page: https://github.com/sponsors/PratikBodawala?frequency=one-time.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests