Hey all, first time Capacitor user (and to some degree Android dev) here.
I’m trying to make an external request to another domain (api.example.com
) but whenever I try running it on my Android phone though Android Studio (npx cap open android
followed by hitting the “play” button" in Studio), the URL in the logcat says https://localhost/api.example.com/...
and I get what amounts to a 404. I do not have this problem when running this app on the server (app.example.com
)
The stack that I’m working with:
SvelteKit 2.0.0,
CapacitorJS: 6.0.0
Node: 20.11.1
Android Studio: 2023.3.1
{
...
"devDependencies": {
"@capacitor/cli": "^6.0.0",
"@sveltejs/adapter-auto": "^3.0.0",
"@sveltejs/adapter-node": "^5.0.1",
"@sveltejs/adapter-static": "^3.0.1",
"@sveltejs/kit": "^2.0.0",
"@sveltejs/vite-plugin-svelte": "^3.0.0",
"@types/eslint": "^8.56.0",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-svelte": "^2.35.1",
"prettier": "^3.1.1",
"prettier-plugin-svelte": "^3.1.2",
"sass": "^1.72.0",
"svelte": "^4.2.7",
"vite": "^5.0.3"
},
"dependencies": {
"@capacitor/android": "^6.0.0",
"@capacitor/core": "^6.0.0",
"@capacitor/ios": "^6.0.0",
"dexie": "^4.0.1",
"uuid": "^9.0.1"
},
...
}
I have tried doing the following in my capacitor.config.json file:
- capacitor.config.json
- adding the URL to the
server.allowNavigation
array ashttps://api.example.com/*
(and without the glob) - setting
server.clearText
totrue
.
- adding the URL to the
- AndroidManifest.xml
- adding the
ACCESS_NETWORK_STATE
andACCESS_WIFI_STATE
permissions (INTERNET
was already there).
- adding the
- CapacitorHttp
- I know this is for patching
fetch
to use native requests instead, but I was having issues in getting this to work with CSRF and POSTing on desktop browsing (didn’t bother trying to build it if I couldn’t get it to work on desktop). Going back to regularfetch
works, so I’m sticking with it unless you all say this is the way to do it.
- I know this is for patching
I admit I haven’t tried many solutions, but I also haven’t been able to find situations similar to mine on the web. I’ve been searching variations of “capacitor android cant make external requests” but I keep finding the same answers from several years ago recommending the above and how it solves their problems.
Is there some config I need to make to allow requests out from the app? Did I botch setting up Capacitor? How can I figure out more information to properly diagnose what’s going on?
I appreciate any help you all can lend!