Android Question Font not found on Android 6, works find on Android 8

nwhitfield

Active Member
Licensed User
Longtime User
In my previously mentioned quest to bring better emoji to my app's users, I'm using the JoyPixels font. There is a specific Android version of the font, called joypixels-android.ttf, which is in the files folder of my project. It's a large file - 22MB.

As part of the app startup, it's initialised along with other fonts, originally in a code module. SInce this error first appeared, I've tried moving it to Application_Resume as well, so the code I have there now says

B4X:
    If joypixels.IsInitialized = False Then
        joypixels = Typeface.LoadFromAssets("joypixels-android.ttf")
    End If

The font file loads perfectly on my main test device with Android 8, and I thought everything was fine, until I tried the latest build on my backup phone, which is Android 6.

Whether I try loading the font in the Main module, or the code module, I get a runtime exception:

B4X:
java.lang.RuntimeException: Font not found /data/user/0/com.bluf.navigator/files/virtual_assets/joypixels-android.ttf.unpacked

I'm curious as to whether there's anything in Android 6 that is causing this problem, or anything I can do to fix the problem directly. Obviously, If this is going to be a problem (and Play console reports the same error on an Android 5 device), I can simply check the android level, and not use the font on older devices, but I'd rather like to have the same visual experience for everyone, which is the main reason for using JoyPixels.
 

DonManfred

Expert
Licensed User
Longtime User
Have you tried to copy the fonts to DirInternal first and the initialize the Typeface from there?
B4A asset are in a special format.
 
Upvote 0

nwhitfield

Active Member
Licensed User
Longtime User
Nope; no difference. I've done a simple test project, and the same thing happens there.
B4X:
Try
    If File.Exists(File.DirAssets,"joypixels-android.ttf") Then Log("File found in assets dir")
    joypixels = Typeface.LoadFromAssets("joypixels-android.ttf")
Catch
    Log(LastException)
End Try

When run on Android 6 and 8 (in release mode), I get the confirmation that the file is found in the assets directory.

On Android 6 I then get

B4X:
(RuntimeException) java.lang.RuntimeException: Font asset not found joypixels-android.ttf
 
Upvote 0

nwhitfield

Active Member
Licensed User
Longtime User
My tentative conclusion is that this is something - I'm not sure what - to do with the API level. Android 8 is API 26, which is the version that allowed fonts to be added as resources. There is, of course, the compatibility library which allows older versions to pull off the same trick, and elsewhere in the app I do indeed use custom fonts, with no issues on Android 6 devices, including the API 23 one I'm testing with here.

I've tried renaming the font file to shorten it, in case that was the issue; again no difference, and exactly the same error - and in any case, the other custom fonts have long names, including hyphens.

So, my hypothesis is that, while the support tools allow for the use of standard fonts as resources on older API versions, there is something that prevents a non-standard font, like this emoji font, from being loaded on those versions. I don't know what, exactly, that issue is, or if it's possible to work round it. But for the time being I'm going with the simple solution of checking the device api level, and only using the joypixels font if >= 26
 
Upvote 0
Top