androidreact-nativereact-hooksfontsexpo

why my expo app's fonts don't work on android but on web it works fine


that is my app in github: https://github.com/Ammar0203/expo

why my expo-react-native app's fonts don't work on android but on web it works fine

it says : (fontFamily "DMRegular" is not a system font and has not been loaded through Font.loadAsync.

it says that for all of the fonts i have searched all the web for a solution non of them worked i'm coding that from a youtube tutorial (Build and Deploy a React Native App | 2023 React Native Course Tutorial for Beginners) https://www.youtube.com/watch?v=mJ3bGvy0WAY&t=418s i have reached to ( 40:58 ) in the video

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

I have tried adding 'react-native.config.js' and i tried the old way Fonts.loadAsync() also i did not add fontWeight property in my stylesheet and also i tried deleting my node_modules folder


Solution

  • I have fixed it my terminal showed me that i need to fix the versions of my modules it said: "Some dependencies are incompatible with the installed expo version: expo-font@11.6.0 - expected version: ~11.4.0 react-native@0.72.3 - expected version: 0.72.5 Your project may not work correctly until you install the correct versions of the packages. Fix with: npx expo install --fix"

    so all i had to do is run in the terminal "npx expo install --fix"