背景:
React Native 0.60+ 版本已经弃用了 react-native link
命令。你需要手动将字体文件添加到项目中。以下是手动配置的方法:
1、准备字体文件
从 Iconfont 网站下载字体文件并解压,获取 .ttf
文件,例如 iconfont.ttf
。
2、将字体放进项目
将 iconfont.ttf
文件放在项目的 assets/fonts
目录中。如果 assets/fonts
目录不存在,请创建它。
3、配置react-native.config.js
在项目根目录创建或修改 react-native.config.js
文件,添加字体文件配置
module.exports = {
assets: ['./assets/fonts']
};
Android 配置
1、在你的项目的 android/app/src/main/assets
目录中创建一个 fonts
文件夹,如果不存在的话
2、将 iconfont.ttf
文件复制到这个 fonts
文件夹中。
3、android/app/build.gradle 代码配置
project.ext.vectoricons = [
iconFontNames: [ 'iconfont.ttf' ] // 指定你的字体文件名
]
apply from: "../../node_modules/react-native-vec