ihhub / fheroes2

fheroes2 is a recreation of Heroes of Might and Magic II game engine.
https://ihhub.github.io/fheroes2/
GNU General Public License v2.0
2.69k stars 375 forks source link

Toolset app crashes on trying to open to select archive #7174

Closed zenseii closed 1 year ago

zenseii commented 1 year ago

Preliminary checks

Platform

Android

Describe the bug

A user on Discord is reporting that the toolset app crashes without a message upon clicking on the option "extract homm2 assets" on their Android 7 tablet.

Version 1.0.3 worked fine.

Save file

No file.

Additional info

No response

zenseii commented 1 year ago

Hi, @oleg-derevenetz. I'll share anything else the user writes here. Do you have any suspicions to why this happens? They have a phone which they are able to use without problems.

Shadic93nh commented 1 year ago

Well Hello its me who reported it. But yeah everything Zense writted is fine but it also count for game app itself it also crashes on start on 1.0.3 everything goes smooth

oleg-derevenetz commented 1 year ago

@zenseii If there is no error message at all, and the extraction works on (I suppose, a bit more modern) phone, but fails on the not-so-modern Android 7 tablet, then I suppose that it may be due to Android OOM (out-of-memory) killer. Does this archive contain homm2.gog file? If yes, what if the user will remove it from the archive?

oleg-derevenetz commented 1 year ago

@Shadic93nh if some resource file was extracted only partially (e.g. animation) and therefore is damaged, the game itself can fail naturally as well. Does it fail on the tablet only or on the phone as well?

Shadic93nh commented 1 year ago

No Oleg on android 13 everything works as intended in both version but not on android 7 tablet which is a huawei mediapad m3 8inch lte on 1.0.3 tablet passes but after updated to 1.0.4 both are not wanting to work tablet has like 4 gb of memory. And no zip contains no homm2.gog as i had prepared all required files

oleg-derevenetz commented 1 year ago

@Shadic93nh then the same questions - does your HoMM2 archive contain homm2.gog file? If yes, what if you remove it from the archive?

Shadic93nh commented 1 year ago

It doesnt like i sayed before. I didnt even tryed to add it as i extracted necessary files from it right to the game. Replying from said android 13 phone

oleg-derevenetz commented 1 year ago

I do not understand anything. What do you mean by "it"? What exactly happens if you try to extract the ZIP archive with the contents of original HoMM2 directory both on phone and on tablet? Does this archive contain homm2.gog file? What if you remove this file from the ZIP archive and try to extract the resulting archive both on phone and tablet?

zenseii commented 1 year ago

It doesnt like i sayed before. I didnt even tryed to add it as i extracted necessary files from it right to the game. Replying from said android 13 phone

Would you be able to provide a screenshot or names of the contents of the heroes 2 archive you have on your phone?

Shadic93nh commented 1 year ago

Sure here is content of my fheroes2 on phone Screenshot_2023-05-13-22-05-14-36_2602b93dc3ef59eeb51bac049073361e

oleg-derevenetz commented 1 year ago

What these "901 MB / 1.36 GB" above mean? What is the size of this ZIP file? If it's the size of the ZIP file (packed size / full size), then it seems too big, because on my phone ZIP file from GOG (full content of GOG directory) takes just ~370 MB.

Shadic93nh commented 1 year ago

Well it only contains files directory from pc version as i was unsure at first if i need it or not. But otherwise works fine and also i have a lot maps added just answering to not make you worried :B. But on tablet i deleted this files folder and it didnt make much difference on 1.0.4. to add without files i added cause i thought android had soundfonts too the whole zip is 379 mb 9mb of added maps

oleg-derevenetz commented 1 year ago

OK @Shadic93nh, @zenseii, I was able to borrow the ancient Lenovo tablet with Android 6, and was able to reproduce the issue. On that device it looks like this:

FATAL EXCEPTION: Thread-17106
Process: org.fheroes2, PID: 23939
java.lang.NoSuchFieldError: No instance field file of type Ljava/lang/String; in class Ljava/nio/file/FileSystemException; or its superclasses (declaration of 'java.nio.file.FileSystemException' appears in /data/app/org.fheroes2-1/base.apk:classes2.dex)
    at j$.desugar.sun.nio.fs.DesugarLinuxFileSystemProvider.createDirectory(SourceFile)
    at j$.nio.file.Files.createDirectory(SourceFile:0)
    at j$.nio.file.Files.createDirectories(SourceFile:0)
    at org.fheroes2.HoMM2AssetManagement.extractHoMM2AssetsFromZip(HoMM2AssetManagement.java:115)
    at org.fheroes2.ToolsetActivity$ToolsetActivityViewModel.lambda$extractAssets$0$org-fheroes2-ToolsetActivity$ToolsetActivityViewModel(ToolsetActivity.java:102)
    at org.fheroes2.ToolsetActivity$ToolsetActivityViewModel$$ExternalSyntheticLambda0.run(D8$$SyntheticClass)
    at java.lang.Thread.run(Thread.java:818)

So it's an issue with java.nio.* desugaring on older Android versions. Android Toolset I/O implementation was recently switched to Java New I/O (java.nio.* ), and desugaring is used (in other words, emulation) of this new API on older Android versions using special libs from Google. But these libs are relatively new and despite the following promises:

You are now free to use the java.nio APIs no matter which Android version is on the user’s device.

there are reports that some part of this emulation may not work on Android 7 or lower devices:

A few features however cannot be emulated for devices running Android 7 and lower and instead throw an instance of UnsupportedOperationException or return null.

so it looks like this very issue.

This emulation is a relatively new feature (this blog post was written in February 2023), so maybe it will be fixed later in more recent versions of these desugaring libs. We can wait until next release and if it will not be fixed, then we can either bump the minimum supported Android version to Android 8 or rewrite the relevant parts without NIO (what I personally would not like to do, because NIO is really handy).

oleg-derevenetz commented 1 year ago

@Shadic93nh if you have Android SDK installed, you can try the following:

oleg-derevenetz commented 1 year ago

On Android 8 (I have my own old Sony Xperia X Compact device with Android 8) everything works just fine, so it seems that these desugaring issues are really observed only on devices with Android 7 or earlier.

Shadic93nh commented 1 year ago

I see. I might just wait or so for now.

oleg-derevenetz commented 1 year ago

It turns out that this issue is observed only with latest version of desugaring libs, but not with the previous one. I downgraded them from 2.0.3 to 2.0.2, and now everything works just fine on my Android 6 tablet.

@Shadic93nh could you please try to install the APK from here (it's in the fheroes2_android.zip archive) on your Android 7 tablet and test it? Please note that this is debug build signed by debug certificate, so you will need to uninstall the version from Google Play first, and, since it's a debug build, it is not optimized, so don't use it to evaluate the game performance on your tablet.