For some reason my compose desktop app crashes in ...
# compose-desktop
t
For some reason my compose desktop app crashes in macOS. The weird part is, it only crashes when I run the exported app/dmg. Not even in the
runDistributable
. How do I get the crashlog in this case?
t
šŸ¤” what’s
app folder
here?
s
If you compile a DMG and then extract the DMG. The contents of the DMG look like an application, but it’s really just a folder that you can open by right clicking and clicking
inspect contents
If you go to your mac applications folder - all of those ā€œapplicationsā€ are just folders.
t
Understood šŸ‘
s
instead of
inspect contents
it’s
show package contents
t
@spierce7 I can the access logs now, but it doesn’t crash when I run the app through this way šŸ˜ž
s
when you double click on the app folder to open the app it crashes?
That sounds like it might be a relative pathing issue for accessing files. Are you accessing files via relative paths at all? Install Bugsnag. You should get the cause of the crash there - https://docs.bugsnag.com/platforms/java/other/
t
this is what happening…
the first launch done via finder. then the second done via
Contents/MacOS/<app name>
s
your app looks nice šŸ™‚ Give bugsnag a shot like I mentioned above.
t
thanks šŸ™‡ Hmmm.. let me try that one also
s
After you initialize it - you can collect logs yourself, and then add them to the bug report via the following:
Copy code
bugsnag.addCallback { report ->
    val logString = logHandler.logs.joinToString(separator = "\n")
    report.addToTab("logs", "log", logString)
}
šŸ‘ 1
t
@spierce7 thanks. I got the culprit!
s
I’ve dealt with file pathing issues a lot when moving between production and dev builds.
t
I see. am a noob in desktop app development šŸ˜„
s
We’re all noobs šŸ™‚ Let me share with you what I’ve learned
šŸ™‡ 1
Inside your gradle script, you can set an
appResourcesRootDir
t
what does it do? šŸ¤”
s
Copy code
compose.desktop {
    application {
        mainClass = "com.blahblah.MainKt"
        jvmArgs += listOf("-Xmx2G")

        nativeDistributions {
            includeAllModules = true
            targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
            packageVersion = versionString
            packageName = "Blah Blah"

            appResourcesRootDir.set(project.layout.projectDirectory.dir("resources"))
They added this after I complained about this issue, but I haven’t seen documentation for it.
I added the above script in the
app
gradle module’s
build.gradle
file. That makes my root
resources
directory
<project root>/app/resources
the resources directory allows you to ship
common
resources for all platforms, but also allow you to ship platform specific resources. If you add any files you want to ship with your application in the
<resource root>/common/
folder, they will be shipped with all platforms.
Then you can get that folder directory in production or development by calling:
Copy code
val resourceRoot = File(System.getProperty("compose.application.resources.dir"))
make sense?
t
Understood šŸ’”
s
I don’t know where you keep the
apk-tool.jar
file, but that would be a way you could access it in a consistent way across app build types.
@theapache64 Are you calling apk-tool.jar via the command line /
ProcessBuilder
?
t
no.. the above exception is happening here . it happens when i create a copy of the
jar
file.
s
I see - so you are including it in your java resources, which packages it in your application jar. Then you are trying to extract it so you can call it?
t
Yes.
s
The resources solution I gave you above removes the need to extract the file. It is shipped extracted.
t
yeah, i think that should help here.
s
šŸ‘ Poke me if that doesn’t solve it for you
t
Sure. will try that maybe tmrw. and will update here šŸ™‚ its sleep time here in India šŸ˜„
šŸ‘ 1
thanks for the help šŸ™‡
s
np
t
@spierce7 The root cause was, when i say
Path("myDir")
in non-dmg build, it was referring to
execution-path/myDir
but in dmg/app build, it was pointing to
/myDir
(root) šŸ˜• since it was a read-only dir, i couldn’t create files in it. that’s why i was getting crash.
s
Yeah
There are a lot of factors
Like where the app is opened from
It's basically amounting to your working directory
t
Understood. Anyway, bugsnag helped a lot in this. thanks šŸ˜„
s
Glad you got it sorted out
So did you end up using the compose resources directory?
Or did you just adjust your path resolution accordingly
t
as of now, fixed the path resolution. but i’ll be moving with
appResourcesRootDir
if it can help me avoid the
Copy code
this::class.java.classLoader.getResourceAsStream
to copy the resources.
but even without
appResourcesRootDir.set(project.layout.projectDirectory.dir("resources"))
,
System.getProperty("compose.application.resources.dir")
was returning a same path šŸ¤”
I am not sure how
appResourcesRootDir
would be helpful in my situation since its a desktop only app
l
How create animated listlazy?
t
@luen wrong thread I guess.