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

bug: Android Capacitor Http Issue "Attempt to invoke virtual method ... getClass" #6479

Closed
h3786010 opened this issue Apr 10, 2023 · 11 comments
Assignees
Labels
needs reproduction needs reproducible example to illustrate the issue platform: android

Comments

@h3786010
Copy link

h3786010 commented Apr 10, 2023

Bug Report

Capacitor Version

@capacitor/cli: 4.7.3
@capacitor/core: 4.7.3
@capacitor/android: 4.7.3
@capacitor/ios: 4.7.3

Platform(s)

Android

Current Behavior

First using Capacitor Http request return the error after launch app
Screenshot_2023-04-06-17-13-02-61_67ee557a188fd8d45d3ec93c08900d76

Expected Behavior

Code Reproduction

https://github.com/h3786010/capacitor-http-bug-repro

App.vue

<script setup>
import { onMounted } from 'vue'
import { CapacitorHttp } from '@capacitor/core'

onMounted(async () => {

  await CapacitorHttp.post({
    url: 'https://mydomain/api/foo',
    headers: {
      "Content-Type": "application/json",
    },
    webFetchExtra: {
      credentials: "include",
    },
  }).then((response) => {
    alert(JSON.stringify(response.data));
  }).catch((error) => {
    alert(error.message);
  })

})
</script>

<template>
  hello world!
</template>

capacitor.config.json

{
  "appId": "com.example.app",
  "appName": "test",
  "webDir": "dist",
  "bundledWebRuntime": false,
  "server": {
    "allowNavigation": [
      "mydomain"
    ]
  },
  "plugins": {
    "CapacitorHttp": {
      "enabled": true
    }
  }
}

Other Technical Details

npm --version 8.19.3

node --version v18.13.0

pod --version output (iOS issues only):

Additional Context

@ionitron-bot ionitron-bot bot added the triage label Apr 10, 2023
@ionitron-bot ionitron-bot bot removed the triage label Apr 10, 2023
@h3786010 h3786010 changed the title Android Capacitor Http Issue "Attempt to invoke virtual method ... getClass" :bug Android Capacitor Http Issue "Attempt to invoke virtual method ... getClass" Apr 10, 2023
@h3786010 h3786010 changed the title :bug Android Capacitor Http Issue "Attempt to invoke virtual method ... getClass" bug: Android Capacitor Http Issue "Attempt to invoke virtual method ... getClass" Apr 10, 2023
@Vansinnesvisor
Copy link

Vansinnesvisor commented Apr 10, 2023

Can confirm, POST requests not working. This issue broke my app release in Android.
Works well with server property in capacitor.config.ts (dev mode).
Currently rollback to 4.7.2.

Same error in Run console
image

@jcesarmobile jcesarmobile added the needs reproduction needs reproducible example to illustrate the issue label Apr 11, 2023
@Ionitron
Copy link
Collaborator

This issue may need more information before it can be addressed. In particular, it will need a reliable Code Reproduction that demonstrates the issue.

Please see the Contributing Guide for how to create a Code Reproduction.

Thanks!
Ionitron 💙

@zarko-tg
Copy link

Is there an actual issue with CapacitorHttp.post on Android?
We're seeing the same kind of error both on device and on emulator when running in prod mode.

code: "NullPointerException"
data: undefined
message: "Attempt to invoke virtual method 'java.lang.Class java.lang.Object.getClass()' on a null object reference"
stack: "Error: Attempt to invoke virtual method 'java.lang.Class java.lang.Object.getClass()' on a null object reference\n at returnResult (http://localhost/:760:32)\n at win.androidBridge.onmessage (http://localhost/:735:21)"

@Ionitron Ionitron removed the needs reply needs reply from the user label Apr 13, 2023
@elenche
Copy link

elenche commented Apr 14, 2023

Same issue here, tested on @capacitor/android versions 4.7.1 and 4.7.3, both on device and simulator. It happens only on the first app installation. On subsequent opens the POST calls work as expected.

@zarko-tg Downgrading to @capacitor/[email protected] solved the issue for me.

$ ionic info

Ionic:
   Ionic CLI                     : 6.16.3 (C:\Users\xyz\AppData\Roaming\npm\node_modules\@ionic\cli)
   Ionic Framework               : @ionic/angular 6.7.1
   @angular-devkit/build-angular : 14.2.11
   @angular-devkit/schematics    : 14.2.11
   @angular/cli                  : 14.2.11
   @ionic/angular-toolkit        : 6.1.0

Capacitor:
   Capacitor CLI      : 4.7.3
   @capacitor/android : 4.7.2
   @capacitor/core    : 4.7.3
   @capacitor/ios     : 4.7.3

Utility:
   cordova-res (update available: 0.15.4) : 0.15.3
   native-run                             : 1.7.2

System:
   NodeJS : v18.12.1 (C:\Program Files\nodejs\node.exe)
   npm    : 8.19.2
   OS     : Windows 10

@adnbrownie

This comment was marked as abuse.

@jcesarmobile
Copy link
Member

Sorry, I missed the link, but sadly, I've tested it now and can't reproduce the issue on the provided app.

A customer has reported a similar issue with a proper reproduction and a coworker is looking into it, so if it turns out being the same issue, it will be fixed soon, but would help if we had a proper reproduction in this issue too so we can verify it's the same issue.

@prajapatijay95

This comment was marked as abuse.

@h3786010
Copy link
Author

Working well after upgrade 4.8.0
Thank You!

need additional settings CapacitorCookies in my app project
capacitor.config.json

"plugins": {
  "CapacitorHttp": {
    "enabled": true
  }
}

to

"plugins": {
  "CapacitorCookies": {
    "enabled": true
  },
  "CapacitorHttp": {
    "enabled": true
  }
}

@adnbrownie
Copy link

I can confirm that the described issue is no longer happening with 4.8.0 when having both CapacitorHttp & CapacitorCookie enabled in capacitor.config.json, as @h3786010 described. Enabling only CapacitorHttp alone does not work, though.

@h3786010
Copy link
Author

h3786010 commented May 2, 2023

@adnbrownie Because my APP works through Session, Maybe CapacitorCookie needs to be explicitly set in version 4.8.0

@jcesarmobile
Copy link
Member

This is fixed in Capacitor 4.8.0 and Capacitor 5.0.0 and newer.
It shouldn't require to set CapacitorCookies to true, I don't get the error on my sample app anymore after updating to 4.8.0 and it doesn't have CapacitorCookies set to true .
For those that it doesn't work unless you add CapacitorCookies set to true, please, create a new issue and provide a sample app where it can be reproduced as that shouldn't be needed.

@ionic-team ionic-team locked as resolved and limited conversation to collaborators May 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs reproduction needs reproducible example to illustrate the issue platform: android
Projects
None yet
Development

No branches or pull requests

9 participants