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

App crashes upon opening a Typst project folder #149

Open
lrq3000 opened this issue May 19, 2024 · 19 comments · May be fixed by #151
Open

App crashes upon opening a Typst project folder #149

lrq3000 opened this issue May 19, 2024 · 19 comments · May be fixed by #151

Comments

@lrq3000
Copy link

lrq3000 commented May 19, 2024

After working beautifully well for a couple of hours, the app started crashing every time I tried to open a Typst project folder.

I know a bit about Android development so I tried to debug with logcat but so far the only thing I can find is that this issue seems to be caused by a DeadObjectException caused by the rustService being called when it is not properly loaded. But this happens right away. I tried to modify the code to ensure it gets loaded, but this does not change anything (maybe I'm doing it wrong, I don't know anything about Rust).

Here is the full trace:

@workspace This app is an Android editor for Typst projects, a new kind of Markdown flavored markup language. When I try to open a Typst folder, the app crashes with the following error, help me debug it. Consider also that the app initially worked fine, but later started to crash with this error, even when the target folder is totally empty, whereas initially it would work fine.

2024-05-19 19:11:25.360 6403-6403 DEBUG pid-6403 A pid: 6310, tid: 6336, name: Binder:6310_3 >>> dev.soupslurpr.beautyxt:typst_project_view_model_rust_library_isolated_process:dev.soupslurpr.beau <<< 2024-05-19 19:11:26.050 5710-5710 AndroidRuntime pid-5710 E FATAL EXCEPTION: main Process: dev.soupslurpr.beautyxt, PID: 5710 android.os.DeadObjectException at android.os.BinderProxy.transactNative(Native Method) at android.os.BinderProxy.transact(BinderProxy.java:532) at D2.O.k(Unknown Source:17) at I2.a0.u(Unknown Source:7) at Q2.a.n(Unknown Source:7) at h3.F.run(Unknown Source:114) at h3.P.T(Unknown Source:23) at m3.a.d(Unknown Source:152) at h3.z.W(Unknown Source:11) at h3.a.i0(Unknown Source:80) at W2.j.m(Unknown Source:29) at I2.b0.onServiceConnected(Unknown Source:58) at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:2154) at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:2186) at android.os.Handler.handleCallback(Handler.java:900) at android.os.Handler.dispatchMessage(Handler.java:103) at android.os.Looper.loop(Looper.java:219) at android.app.ActivityThread.main(ActivityThread.java:8393) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1055) Suppressed: m3.f: [o0{Cancelling}@57b1494, Dispatchers.Main.immediate]

Thank you for making this awesome tool, I hope it can work on my device.

@lrq3000
Copy link
Author

lrq3000 commented May 19, 2024

Ok I think I know the culprit, it's the scoped storage management. I'm not entirely sure, but what I'm sure is that now I can systematically reproduce the exception, and also the app working fine, by doing the following:

  1. first, click on Create, then select Typst project, then create a new folder, then select it as the project's root. Now, the project works.
  2. close the app, and reopen it. Now click on Open, Typst Project, and then select the same folder you just created: it should work fine.
  3. Now close the app, reopen it, then click on Create, Typst project, and create a new folder somewhere else.
  4. Now if you try to Open, Typst project and reopen the 2nd folder, it will work fine. But if you try to reopen the first folder we created earlier, it will crash.

This is typical of an issue with fetching the permissions to access and modify files with scoped storage. I may be able to help but your codebase is hard for me to understand because of the Rust calls and background process.

I suggest to use the SimpleStorage library to avoid such tricky errors, that's what I did to improve some other projects in the past such as Super Productivity.

lrq3000 added a commit to lrq3000/BeauTyXT that referenced this issue May 20, 2024
…age permission issues (fixed via anggrayudi's SimpleStorage lib) (fixes soupslurpr#149)

Signed-off-by: Stephen L. <LRQ3000@gmail.com>
@lrq3000
Copy link
Author

lrq3000 commented May 20, 2024

Bingo, this was the issue! I'm making a PR right now.

@soupslurpr
Copy link
Owner

Odd, I can't reproduce this issue with the steps you provided. Could you inform me of the device you're using and OS?

@lrq3000
Copy link
Author

lrq3000 commented May 21, 2024

Android 10, the SAF show these issues only from Android 10 (SDK version 29) and up because Google made it much more difficult to use it and much less permissive. Normally you should be able to reproduce it in the Android Studio emulator using Android 10 or above.

@soupslurpr
Copy link
Owner

@lrq3000 I'm using the emulator using the "Pixel 7 API 34" device and it's still not working, I made a screen recording and posted to the YouTube video linked below just in case I'm doing something wrong.

https://youtu.be/C5eV1zPnfIQ

@lrq3000
Copy link
Author

lrq3000 commented May 22, 2024

Thank you for posting the video, so my instructions seem to be wrong. I'm not sure under which conditions the app can lose the permissions to a folder it created, but it happened randomly to me just by waiting less than 24h.

Instead, try the following:

  • create a folder and a main.typ file with any external tool (ie, not using BeauTyXT)
  • try to open the folder with BeauTyXT (not create, just open, since the folder already exists)

This should normally crash.

@lrq3000
Copy link
Author

lrq3000 commented May 22, 2024

I just tested on Android 14 API 34 (Pixel 8) in an emulator, if you try to access a folder you did not create with the app, you either get asked again to select a folder, or you get a crash, like on Android 10.

To do that, I created a folder (typsttest) using the native Files app, then created a markdown file using BeauTyXT or another text editor outside of the folder I created, then copied it into the folder (so that it doesn't have a lock on it), then rename it to be main.typ , then try to open the folder typsttest.

(In a previous message, I stated that an error message was displayed, but that's not the case, the message was just shown on any non user folders in the folder picker dialog, which is irrelevant for this issue).

@lrq3000
Copy link
Author

lrq3000 commented May 22, 2024

Update: my PR does not fix the crash on Android 14. Something must have changed in the SAF... bummer. I'm going to try to fix that.

@lrq3000
Copy link
Author

lrq3000 commented May 22, 2024

Update2: in fact it's not an issue with my PR but with my emulator/compilation: since I reused the libraries you provided instead of compiling my own, it seems I can only target ARM_64, not x86_64 (which is what the emulator uses). I tried running ARM_64 but it is extremely slow and does not boot up because of the lack of Intel HAXM. The alternative is to use Genymotion which works fine with ARM_64 images, but it currently is incompatible with the latest version of Android Studio...

TL;DR: I can only run my APK on ARM64, so I can't test in emulators. You will have to test my PR please, or wait a month when I'll have a bit more time to try to compile everything. I believe my PR works fine.

@soupslurpr
Copy link
Owner

soupslurpr commented May 22, 2024

@lrq3000 It seems UPX breaks the x86_64 library (in emulators only?), I think I'll have to stop using it since it isn't very reliable. Try skipping compressing the library with UPX.

I pushed a commit to remove the usage of UPX in useful_commands.txt.

@lrq3000
Copy link
Author

lrq3000 commented May 23, 2024 via email

@soupslurpr
Copy link
Owner

Could you tell me the specific device or specific OS (like Samsung One UI 5.0 or Google Pixel 8 Android 14 etc)

@lrq3000
Copy link
Author

lrq3000 commented Jun 2, 2024

It's a Huawei P40 Pro Plus with Android 10. But I think this is not specific to my phone, as I think I cannot reproduce anymore because now the app has write permissions that the OS remembers. I will test with another phone later on which I never installed BeauTyXT but I am too busy currently, I'll follow up in about two weeks (from the 17th June onward).

If I cannot reproduce the issue then, I will modify my PR to extract the other features I implemented (eg, background preview refresh in another thread, etc).

@soupslurpr
Copy link
Owner

The background preview refresh doesn't work like you might think, it still blocks other functions in the Rust library. It only makes it asynchronous in Kotlin but it gets blocked when calling another Rust function anyways. So when trying to type text it still blocks it. It has no effect.

The proper way to implement it would be to make it async on the Rust side. Which I'm not sure can be done with an isolatedProcess service. I haven't tried.

However, I don't think it's needed at all if refreshing only the page(s) you actually see in the preview render is something viable to implement.

@lrq3000
Copy link
Author

lrq3000 commented Jun 2, 2024

Did you try my build? Because for me it works fine, the preview is indeed refreshed in a non blocking way.

I have a a 4 pages document with 2 includes and it is extremely slow, i think this can be considered a small document.

@soupslurpr
Copy link
Owner

I tried the latest build posted on your fork, typing out the characters is still blocked on the preview refreshing.

@lrq3000
Copy link
Author

lrq3000 commented Jun 3, 2024

That is very strange. Are you still using the same emulator setup you cited above? I will try to recompile according to your updated instructions and see if there is maybe a difference due to Android OS versions.

@soupslurpr
Copy link
Owner

I'm using a real device, the Pixel 7 on GrapheneOS (Android 14)

@lrq3000
Copy link
Author

lrq3000 commented Jun 3, 2024

Ok thank you, i will try to make an emulator although sometimes there are differences with real devices, but at leart it will be more reproducible (as I am also using a real device since I could not run in the emulator before )

I'll keep you updated from the 17th june onward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment