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

Can't use fonts #87

Closed
wilsonowilson opened this issue Sep 6, 2021 · 20 comments
Closed

Can't use fonts #87

wilsonowilson opened this issue Sep 6, 2021 · 20 comments

Comments

@wilsonowilson
Copy link

I can't seem to add a custom font to my project built with nativeshell. Trying to add a font to the pubspec.yaml causes the build to fail with this error:

Stderr:
  [  +67 ms] Error: unable to locate asset entry in pubspec.yaml: "fonts/Inter/Inter-Regular.ttf".
  [  +11 ms] Target debug_macos_bundle_flutter_assets failed: Exception: Failed to bundle asset files.
             #0      copyAssets (package:flutter_tools/src/build_system/targets/assets.dart:61:5)

I have confirmed the path to the asset is correct, and I have used the exact same configuration on another project to be sure.

@knopp
Copy link
Contributor

knopp commented Sep 6, 2021

This could definitely be issue with nativeshell build. Given that some flutter targets litter the root project structure with ephemeral files as a workaround nativeshell runs the actual flutter build in a subfolder inside build folder. It does create symlinks for assets, but there might be cases where it doesn't work correctly. Is there a repository I can reproduce this with?

@wilsonowilson
Copy link
Author

Not that I have publicly available, but I think trying to add a custom font to the nativeshell examples might produce the same error. I'll try and see immediately

@wilsonowilson
Copy link
Author

Trying to add a custom font to the example project produces this error:

  Stderr:
  [        ] Unexpected child "example" found under "flutter".
  [   +8 ms] Please correct the pubspec.yaml file at /Users/wilson/Developer/Experimenting/examples/target/x86_64-apple-darwin/debug/build/nativeshell_examples-c92add7ebd1546ee/out/flutter/pubspec.yaml

@knopp
Copy link
Contributor

knopp commented Sep 6, 2021

That seems like a flutter tool error. Are you sure the pubspec.yaml is correct? Can you post it here?

@wilsonowilson
Copy link
Author

My bad, the pubspec.yaml file was not correctly formatted. Trying again on the app template yielded the same error:

  Stderr:
  [  +50 ms] Error: unable to locate asset entry in pubspec.yaml: "fonts/Inter/Inter-Regular.ttf".
  [   +5 ms] Target debug_macos_bundle_flutter_assets failed: Exception: Failed to bundle asset files.
             #0      copyAssets (package:flutter_tools/src/build_system/targets/assets.dart:61:5)

@knopp
Copy link
Contributor

knopp commented Sep 6, 2021

Can you post the whole pubspec.yaml? Just in case. I'll try to reproduce this tomorrow.

@wilsonowilson
Copy link
Author

Sure!

name: app_template
description: NativeShell application template
publish_to: 'none'
version: 1.0.0+1
environment:
  sdk: ">=2.12.0-214.0.dev <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  pedantic: ^1.9.2
  path: ^1.7.0

  cupertino_icons: ^1.0.0
  nativeshell:
    version: ^0.1.9

dev_dependencies:
  flutter_test:
    sdk: flutter

flutter:
  uses-material-design: true
  fonts:
    - family: Inter
      fonts:
        - asset: fonts/Inter/Inter-Regular.ttf
        - asset: fonts/Inter/Inter-Bold.ttf
          weight: 700
        - asset: fonts/Inter/Inter-Black.ttf
          weight: 900    

@wilsonowilson
Copy link
Author

I can upload the project to a temporary repository if that helps

@wilsonowilson
Copy link
Author

Here's the app template with fonts included: https://github.com/wilsonowilson/app_template

@knopp
Copy link
Contributor

knopp commented Sep 6, 2021

Sure, it won't harm :) Or at least the fonts folder. But I think the problem is that nativeshell only recognizes flutter/assets, it ignores flutter/fonts at this point. The functionality will need to be added in flutter_build.rs (copy_pubspec_yaml)

@wilsonowilson
Copy link
Author

I initially tried with an assets folder. Let me update the example and see if that works.

@knopp
Copy link
Contributor

knopp commented Sep 6, 2021

I think for now you can manually add the fonts in flutter/assets so that they get copied.

@wilsonowilson
Copy link
Author

In the flutter sdk?

@knopp
Copy link
Contributor

knopp commented Sep 6, 2021

No, I meant specifying the font files as flutter assets in pubspec.yaml (https://flutter.dev/docs/development/ui/assets-and-images)

@knopp
Copy link
Contributor

knopp commented Sep 6, 2021

Something like this should work:

flutter:
  assets:
    - fonts/

It should force nativeshell build to link the fonts folder.

@wilsonowilson
Copy link
Author

Ah, gotcha. I guess if I wanted to use fonts that way, I'd have to use the FontLoader, correct?

@wilsonowilson
Copy link
Author

Oh I think I misunderstood. It just helps nativeshell create a link, right?

@knopp
Copy link
Contributor

knopp commented Sep 6, 2021

No, you should be able to have both in pubspec.yaml

flutter:
  uses-material-design: true
  assets:
    - fonts/
  fonts:
    - family: Inter
      fonts:
        - asset: fonts/Inter/Inter-Regular.ttf
        - asset: fonts/Inter/Inter-Bold.ttf
          weight: 700
        - asset: fonts/Inter/Inter-Black.ttf
          weight: 900    

I haven't test this but it should work. The assets/fonts part is there just so that nativeshell makes the proper symlink before running the build.

In any case, this is a bug and it should be fixed properly.

@knopp
Copy link
Contributor

knopp commented Sep 6, 2021

Oh I think I misunderstood. It just helps nativeshell create a link, right?

Right.

@wilsonowilson
Copy link
Author

Works like a charm! Thanks for the help!

@knopp knopp closed this as completed in ca3ac70 Sep 19, 2021
knopp added a commit that referenced this issue Sep 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants