#How to build sveltekit app apk with tauri ?
96 messages ยท Page 1 of 1 (latest)
There aren't any resources about it (assuming you mean an Android apk)
https://github.com/simonhyll/devcontainer
This devcontainer I've made is a pretty good starting point for setting up a container that can build an Android Tauri app
As for the sveltekit part, that's up to you, shouldn't be any particulars about it beyond the basic desktop setup, the only specifics for mobile is related to running the dev server with what ip you use and what not, but the build itself is the same for android as it is for desktop
Hello! I've tried to build it and I'm getting quite a few errors
Lets see them, hard to help you without knowing what you're seeing ๐
I'm rebuilding it to show you the errors x)
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
It wouldn't happen to be a version 1 project you're compiling, and have only updated the dependency versions? There's more that needs to be done to migrate from v1 to v2 than just upgrading the version numbers
Also it looks like you're using a really, really old version, alpha.9, we're at alpha.20 right now
When using the alpha it's important to stay up to date ๐
Are you talking about the CLI? I just copied and pasted the Dockerfile haha
I'm going to try to update everything
Yea I haven't touched the dockerfile in a while, updates are needed ๐
Oh okay xD By the way, I saw that you were installing pnpm, but shouldn't I use npm for my project?
Oh, I didn't say anything x) It's already there
The choice between npm, pnpm, yarn or bun is entirely up to you
But spoiler alert, npm is the wrong choice, you should use either pnpm or yarn, they do literally the same job but faster and with fewer annoying things, like, with npm you need an extra -- to pass options, and you always need to add run
So instead of running npm run tauri build -- --debug for example you can run pnpm tauri build --debug. Plus pnpm is a billion times faster at downloading and installing assets
Yarn is generally easier to use than pnpm and more stable
Pnpm is cooler than yarn and you should use it until it breaks
Bun is even cooler still because it's even faster than the others, like, literally millisecond install times the second time you install a package
NPM is bad, dont use it
All those package managers download packages from the same repository, npmjs.com, they just operate differently client side
I know all that, but it wasn't my choice ๐ , it's for an academic project due tomorrow and the person who was going to make the mobile application in flutter let us down so we finally said we'd switch to tauri
Normally I'm more on the backend side ๐คฃ
However, I wouldn't hesitate to use Tauri again, it's incredible!
I tried this:
FROM tatata
WORKDIR /app
COPY . .
RUN npm install
RUN npm run tauri android build -- --debug
tatata is the devcontainer dockerfile
0.650 > tauri build --debug
0.650
0.689 Error failed to open Cargo.toml for rewrite: Permission denied (os error 13)
------
Dockerfile:9
Okay I fixed it but I have no apk built
Did you extract it from the docker image?
I've just succeeded, that's because I was building the desktop version xD
It works great thank you! Well now I have a fetch problem that won't take my cookies but I'll find a solution x)
@peak sleet Excuse me, do you have any idea why tauri doesn't support very well the fetch method ?
We are not receiving headers in the response
Yet if I check the network panel in the desktop app
the headers are present
w00t? ๐ The native web fetch method is handled by the webview itself, there should be nothing Tauri related interfering with that. Without seeing your code my best guess would be sending them with fetch improperly? ๐
Could also be some CORS setting for your server
CORS can prevent headers from being sent
However I've made sure that it's not checked, and when I launch my site in dev mode I don't have any CORS problems, but I do with tauri. I saw at one point that the origin was something like tauri://.
Maybe that's why ?
On Linux (and Mac I think) the built app has the origin tauri://localhost, while on Windows (I think only?) it's http://tauri.localhost
During development it's ofc your dev servers url
maybe my express server refuses when it doesn't come from http?
That sounds like the most likely option yep. Add CORS middleware if you havent and for resting purposes allow everything (having no CORS middleware in Express still enforces some stuff)
If I disable CORS my deployment version doesn't work anymore xD
I'm trying this, to accept everything:
const app = await NestFactory.create(AppModule);
app.enableCors({
origin: true,
credentials: true,
});
Same :/
Here's how I do my fetch:
try {
const response = await fetch(`${API_URL}/auth/login`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
credentials: 'include',
body: JSON.stringify({email, password})
});
const jsonResponse = await response.json();
if (!response.ok)
return Promise.reject(jsonResponse as BackendResponse);
return Promise.resolve(jsonResponse as BackendResponse);
} catch (error) {
throw new Error(`Error fetching user data: ${error}`);
}
Do you import fetch from Tauri or are you using the native fetch?
And you don't get any errors on your client side?
It's just missing response headers?
If that's the case and the headers that the server receives are what you expect, then it's definitely something to do with how the server handles the request.
The issue is that you're using .json() to only return the JSON part of the response ๐
Oh... I thought that screenshot above was from the Network tab for some reason.
I had this:
const response = await fetch(`${API_URL}/auth/login`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
credentials: 'include',
body: JSON.stringify({email, password})
});
console.log('response_headers', response.headers)
const jsonResponse = await response.json();
if (!response.ok)
return Promise.reject(jsonResponse as BackendResponse);
return Promise.resolve(jsonResponse as BackendResponse);
Isn't that the right solution to show headers?
Ah you did do the print there, then yea that should be showing something (unless you're dealing with an HttpOnly cookie?)
Ok so first of all, HttpOnly = prevent javascript from accessing it
Second of all, you shouldn't be dealing with access tokens in javascript
When your API logs you in and sets the HttpOnly cookie, JavaScript cant use it, but every subsequent request you make to that API will automagically have the cookie attached to it
It's security best practises
You don't use JS to e.g. store the token in LocalStorage
yeah but the credentials include doesn't work
So it's not a HttpOnly issue, am I right ?
Maybe because of the domain in res.cookie ?
HttpOnly is the reason you're not seeing it in javascript
The domain you set for the cookie should be the domain of your API
The domain you set is the domain fetch will then use for automagically attaching the cookie to all requests going to that domain
yeah, but i'm using the production api
on localhost
If I start the backend on localhost it works
Because you have secure as well, which the Tauri origin isn't since it's not https
At least afaik
how can I accept localhost origins? Because I couldn't put the ip of all my users who have the mobile app haha
By disabling secure in the cookie, but that'll have its own issues. It's better to get around all this by using reqwest in the Rust end, there you can set up proper secure communication and what not. It's more advanced but it's worth it if you care about security
Right now I just want it to work so I can present the functional project to my school tomorrow xDD
i try to disable secure in the cookie
In that case yea toss that secure out of there, it just enforces that the cookie is only passed to the domain you specified if it's using proper https based communication, which for a school project f*ck it x)
Still the same, I just left the domain because otherwise it doesn't work on the production side 
res.cookie('access_token', jwt, {
domain: process.env.COOKIE_DOMAIN ?? 'localhost',
});
app.enableCors({
origin: [
'http://localhost:3000',
'http://localhost:5173',
'tauri://localhost',
'https://lfdp.eu',
'http://lfdp.eu',
],
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE,OPTIONS',
credentials: true,
});
and headers still empty ๐ฎ
console.log(document.cookie)
empty too
And there's absolutely no way you can just email the token to the user and tell them to enter it manually? ๐
xDDD
It's 1:21 here atm and my tired humor is at its peak
same for me :x
And tomorrow I'm getting up very early so I'm trying to fix it as soon as possible xD
And we need a mobile app, otherwise it's 0 ๐ฎ
Oh dear, Tauri being in alpha for mobile might be an issue then ๐
But yea at this point the only feasible way for me to debug this would be to clone your repo, backend and frontend, and actually do hands on debugging, and that's so, so much effort ๐ฉ
Based on everything I can think of there's nothing that should be preventing fetch from receiving headers, I did look it up and Set-Cookie headers shouldn't be showing in response.headers, but they should definitely be showing in document.cookie. So afaik your backend is correctly responding with a Set-Cookie header, it's not limiting it whatsoever aside from the domain part, your webview should be receiving the cookie
The last idea I have is CSP settings client side
Wait now the apk is not building anymore 
553.6 error[E0063]: missing field `license` in initializer of `PackageSettings`
553.6 --> /home/vscode/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tauri-cli-2.0.0-alpha.20/src/interface/rust.rs:886:28
553.6 |
553.6 886 | let package_settings = PackageSettings {
553.6 | ^^^^^^^^^^^^^^^ missing `license`
553.6
553.6 error[E0063]: missing field `files` in initializer of `MacOsSettings`
553.6 --> /home/vscode/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tauri-cli-2.0.0-alpha.20/src/interface/rust.rs:1207:12
553.6 |
553.6 1207 | macos: MacOsSettings {
553.6 | ^^^^^^^^^^^^^ missing `files`
553.6
554.1 For more information about this error, try `rustc --explain E0063`.
554.2 error: could not compile `tauri-cli` (lib) due to 2 previous errors
554.2 warning: build failed, waiting for other jobs to finish...
555.2 error: failed to compile `tauri-cli v2.0.0-alpha.20`, intermediate artifacts can be found at `/tmp/cargo-installtG35IT`.
555.2 To reuse those artifacts with a future compilation, set the environment variable `CARGO_TARGET_DIR` to that path.
------
Dockerfile:189
--------------------
I think I'll go to sleep it's too much xD