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

Resource files not being available under the iOS target #6

Open
sjmp93 opened this issue Sep 25, 2024 · 7 comments
Open

Resource files not being available under the iOS target #6

sjmp93 opened this issue Sep 25, 2024 · 7 comments
Labels
bug Something isn't working

Comments

@sjmp93
Copy link

sjmp93 commented Sep 25, 2024

We are trying to use FontAwesome FontIcons in a CMP view and it works fine under the Android target but, under the iOS target, we are receiving this error at Xcode console after loading the CMP view:

Uncaught Kotlin exception: org.jetbrains.compose.resources.MissingResourceException: Missing resource with path:
/private/var/containers/Bundle/Application/RANDOM-FOLDER-FOR-MY-APP/MyAp.app/compose-resources/composeResources/dev.tclement.fonticons.fa.solid.resources/font/fontawesome_solid.otf

I believe that there is a plugin to do the resouces copy task, but I couldn't find a to use it. I refer to the multiplatform-structure plugin, wich is used in your testApp sample.

@tclement0922
Copy link
Owner

The plugin is internal to this library, you can find its source code here. However I don't think it is the cause of your issue, I just checked on Maven Central and it seems the font is correctly uploaded for Apple targets.

The official documentation says that "your project needs to use Kotlin 2.0.0 or newer and Gradle 7.6 or newer" for publication, but this maybe also applies to your case, what version of Kotlin and Gradle are you using?

@tclement0922 tclement0922 added the bug Something isn't working label Sep 25, 2024
@sjmp93
Copy link
Author

sjmp93 commented Sep 25, 2024

The plugin is internal to this library, you can find its source code here. However I don't think it is the cause of your issue, I just checked on Maven Central and it seems the font is correctly uploaded for Apple targets.

The official documentation says that "your project needs to use Kotlin 2.0.0 or newer and Gradle 7.6 or newer" for publication, but this maybe also applies to your case, what version of Kotlin and Gradle are you using?

We use Gradle 8.0.0 and Kotlin 1.9.20 so its probably the cause of this error. I'll try to update to Kotlin 2.0.0 in order to see if it solves my issue, but first I'm writting a build script for Xcode that copies the .otf files inside the app bundle.

@sjmp93
Copy link
Author

sjmp93 commented Sep 25, 2024

The plugin is internal to this library, you can find its source code here. However I don't think it is the cause of your issue, I just checked on Maven Central and it seems the font is correctly uploaded for Apple targets.
The official documentation says that "your project needs to use Kotlin 2.0.0 or newer and Gradle 7.6 or newer" for publication, but this maybe also applies to your case, what version of Kotlin and Gradle are you using?

We use Gradle 8.0.0 and Kotlin 1.9.20 so its probably the cause of this error. I'll try to update to Kotlin 2.0.0 in order to see if it solves my issue, but first I'm writting a build script for Xcode that copies the .otf files inside the app bundle.

Ok, the script effectively copies the files inside the app bundle but the problem still happens. I'll try to update to Kotlin 2.0.0 to check if it solves the issue.

@sjmp93
Copy link
Author

sjmp93 commented Sep 28, 2024

Finally we took the following approach:

  • Given the lib itself works well in both platforms, we've decided to keep using it because It provides a good way to use each font glyph.
  • To avoid the kotlin 2.0.0 update requirement, we use our own .otf file for fontawesome fonts (pro version) in the font directory inside the composeResources directory, so we can use the lib constants mapping to the Unicode value of each glyph if it belongs to the free version of fontawesome. In this way, iOS platform is capable to access the resources files of our own package.
  • For the pro glyphs, we implement new constants as well as a new rememberFontawesomePro() method in order to reference our .otf file (this new method is also user for the existing constants, so, as pro version shares the same Unicode value for each glyph, we can use your constants to reference each glyph inside our fontawesome pro font resource).

@tclement0922
Copy link
Owner

So was that caused by the Kotlin version? If it is I might add a warning to the README about this.

we use our own .otf file for fontawesome fonts (pro version)

Oh yeah if you're using the pro version you should do that and simply use font-fa instead of font-fa-solid.

For the pro glyphs, we implement new constants

I thought about adding an additional module for the Pro icons constants, but as far as I know a Pro subscription is required to download the pro icons.json and it might break their ToC to use it in a public project.

@sjmp93
Copy link
Author

sjmp93 commented Oct 1, 2024

So was that caused by the Kotlin version? If it is I might add a warning to the README about this.

we use our own .otf file for fontawesome fonts (pro version)

I'm not completely sure because the update is difficult for us because of other dependencies we have, but I can assure that with Kotlin 1.9.20 and using our own .otf file inside composeResources and with the workaround that I mentioned before, FontIcon composables are working perfectly.

I thought about adding an additional module for the Pro icons constants, but as far as I know a Pro subscription is required to download the pro icons.json and it might break their ToC to use it in a public project.

Related to this sentence, yep, a Pro subscription is required, but we have that. As a proposal (I'll try to create a pull request to add this), it would be a good idea to add a mechanism that enable users to add their own .otf files as we do. If I'm not wrong, this mechanism would need to be implemented in the plugin module, in order to generate all the helper code needed to make the custom added fonts (i.e. FontAwesome Pro) easy to access in the entire module scope that applies the plugin.

@tclement0922
Copy link
Owner

I'm not completely sure because the update is difficult for us

I'll just leave this issue open then, I don't really know what is causing it and I can't test it as I don't have a mac.

it would be a good idea to add a mechanism that enable users to add their own .otf files as we do

That is basically what the core library already does, see rememberStaticIconFont for your use case. You can simply do something like this:

val iconFont = rememberStaticIconFont(fontResource = Res.font.fontawesome_solid_pro)

If I'm not wrong, this mechanism would need to be implemented in the plugin module

The plugin module only provides a way to reduce duplicated code in the project Gradle files, it is not meant to be used outside this repo.

in order to generate all the helper code needed to make the custom added fonts

Do you mean the icon constants, or the font constructor (like rememberSolidFontAwesomeFont)? If you mean the icon constants, that would be pretty hard considering each font might have a different way to describe their icons list. If you mean the font constructor, as I said above this is already in the core library, no need to add a module to do that.

Also, correct me if I'm wrong, but I think you are using the pro font alongside the font-fa-solid module. If that is the case, I suggest you to simply use the font-fa module.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants