问题
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?
回答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:
- 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:
- Move those fonts to a top-level app directory (e.g. google_fonts).
- 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!)
回答2:
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.
来源:https://stackoverflow.com/questions/61710099/some-package-not-included-in-final-apk-build-in-flutter