0

I have made a simple test app that displays Hello World! in Flutter. I used GoogleFonts package to change fontFamily. When I run it in Android Studio, everything works fine. But in the final build, the styling was reverted back to default Roboto. When I used Android Studio's 'Analyze APK' feature, I found out that GoogleFonts package was not included in the final build. What could be the problem? Is this a bug, or am I doing it wrong?enter image description here

Eric Sison
  • 199
  • 2
  • 3
  • 11

2 Answers2

1

google_fonts package is only use for testing purpose, once you finalises your font's you have to download and add that fonts in assets as we do with images and videos.

This is also mention in official documentation.

The google_fonts package will automatically use matching font files in your pubspec.yaml's assets (rather than fetching them at runtime via HTTP). Once you've settled on the fonts you want to use:

  1. Download the font files from https://fonts.google.com. You only need to download the weights and styles you are using for any given family. Italic styles will include Italic in the filename. Font weights map to file names as follows:
  2. Move those fonts to a top-level app directory (e.g. google_fonts).
  3. Ensure that you have listed the folder (e.g. google_fonts/) in your pubspec.yaml under assets.

Note: Since these files are listed as assets, there is no need to list them in the fonts section of the pubspec.yaml. This can be done because the files are consistently named from the Google Fonts API (so be sure not to rename them!)

Community
  • 1
  • 1
Viren V Varasadiya
  • 25,492
  • 9
  • 45
  • 61
  • Oh wow! I didn't know that! But actually, this is just a test app for a project I'm doing. And I face similar problem. I am using `http` package. But in the final APK build, `http` package is no longer included.. – Eric Sison May 10 '20 at 10:13
  • how you are saying that http package is no longer ? – Viren V Varasadiya May 10 '20 at 10:14
  • Yes. I made sure the I included it in the pubspec.yaml.. But when I build apk file, the `http` package is no longer there, causing my app not to fetch data from an external API resource.. – Eric Sison May 10 '20 at 10:16
  • make sure that there is no internet issue and also make sure you added internet and wifi permissions. https://stackoverflow.com/a/54984295/7924072 – Viren V Varasadiya May 10 '20 at 10:25
  • Yes, I have included the internet permissions in my manifest file, and no internet issues.. – Eric Sison May 10 '20 at 10:28
  • did you make sure that you mistakenly not added package in dev_dependencies: insted of dependencies ? @EricSison – Viren V Varasadiya May 13 '20 at 04:42
0

I have never used the APK Analyzer from Android studio for Flutter APK's, but when I analyze a properly working flutter APK, I see that the includes libflutter.so and libapp.so. The structure of a Flutter is certainly different from a regular Android APK. The packages are included in libapp.so and not added as separate libraries like they are in native Android APKs.

To clarify: on native Android APKs you will see the external libraries that the APK is using on Flutter APKs you will not see the external flutter libraries, they seem to be included in libapp.so and/or libflutter.so.

Mr. Tekneurt
  • 91
  • 1
  • 3
  • With my other project (with similar problem as this test app), I have different other packages included - `progress_dialog`, `font_awesome_flutter`, and `http`. In the APK Analyzer, `progress_dialog` and `font_awesome_flutter` are the only ones included in the final build, but not `http`. Yes, my device has access to internet when testing the app.. – Eric Sison May 10 '20 at 10:26
  • In APK Analyzer, I can see `progress_dialog` and `font_awesome_flutter` under packages folder, but not `http`.. – Eric Sison May 10 '20 at 10:34