You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Expo React Native安卓端字体加载失败,Web端正常问题求助

Expo React Native安卓端自定义字体加载失败问题
  • 开发背景:跟随React Native 2023入门教程开发,当前进度到40分58秒
  • 问题现象:Web端字体显示正常,但安卓端所有自定义字体均加载失败,报错信息如下:
    fontFamily "DMRegular" is not a system font and has not been loaded through Font.loadAsync.
    1. 若您使用系统字体,请确保名称输入正确且设备系统支持该字体。
    2. 若为自定义字体,请务必通过Font.loadAsync加载。
    
  • 已尝试无效的解决方案:
    • 添加react-native.config.js配置文件
    • 改用旧版Font.loadAsync方法加载字体
    • 移除样式表中的fontWeight属性
    • 删除并重新安装node_modules

Layout组件代码:

import { Stack } from "expo-router";
import { useCallback } from "react";
import { useFonts } from "expo-font";
import * as SplashScreen from 'expo-splash-screen'

SplashScreen.preventAutoHideAsync()

const Layout = () => {
  
  const [fontsLoaded] = useFonts({
    DMBold: require('../assets/fonts/DMSans-Bold.ttf'),
    DMMedium: require('../assets/fonts/DMSans-Medium.ttf'),
    DMRegular: require('../assets/fonts/DMSans-Regular.ttf'),
  })
  
  const onLayoutRootView = useCallback(async () => {
    if(fontsLoaded) {
      await SplashScreen.hideAsync()
    }
  }, [fontsLoaded])

  if(!fontsLoaded) {
    return null
  }

  return <Stack onLayout={onLayoutRootView} />
}
export default Layout

内容的提问来源于stack exchange,提问作者Ammar Abbara

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.09 16:33:24