Flutter 的最终 APK 构建中未包含某些包 [英] Some Package not included in final APK build in Flutter

查看:28
本文介绍了Flutter 的最终 APK 构建中未包含某些包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个简单的测试应用,它在 Flutter 中显示 Hello World!.我使用 GoogleFonts 包来更改 fontFamily.当我在 Android Studio 中运行它时,一切正常.但在最终版本中,样式恢复为默认的 Roboto.当我使用 Android Studio 的分析 APK"功能时,我发现 GoogleFonts 包未包含在最终版本中.可能是什么问题呢?这是一个错误,还是我做错了?

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?

推荐答案

google_fonts 包仅用于测试目的,一旦您最终确定字体,您必须下载该字体并将其添加到资产中,就像我们处理图像和视频一样.

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.

官方文档中也提到了这一点.

google_fonts 包将自动使用 pubspec.yaml 资产中匹配的字体文件(而不是在运行时通过 HTTP 获取它们).确定要使用的字体后:

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. https://fonts.google.com 下载字体文件.你只需要下载用于任何给定的权重和样式家庭.斜体样式将在文件名中包含斜体.字体权重映射到文件名如下:
  2. 将这些字体移动到顶级应用目录(例如 google_fonts).
  3. 确保您已在您的文件夹中列出了文件夹(例如 google_fonts/)资产下的 pubspec.yaml.
  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.

注意:由于这些文件被列为资产,因此无需在 pubspec.yaml 的字体部分列出它们.之所以可以这样做,是因为这些文件的名称始终来自 Google Fonts API(因此请确保不要重命名它们!)

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!)

这篇关于Flutter 的最终 APK 构建中未包含某些包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆