类型错误:无法读取属性“UIAppFonts”将自定义字体与 React Native 项目链接时为 null

发布于 2025-01-13 23:13:45 字数 3653 浏览 3 评论 0原文

我正在尝试将自定义字体应用于我的反应本机应用程序。当我运行此命令时

react-native link or yarn react-native link

,当我尝试将自定义字体链接到我的应用程序时,它会出现以下错误,

info Linking assets to ios project
error Linking assets failed.
TypeError: Cannot read property 'UIAppFonts' of null
    at Object.linkAssetsIOS [as copyAssets] (C:\Users\saran\Documents\GitHub\estate-92-mobile\node_modules\@react-native-community\cli-platform-ios\build\link\copyAssets.js:89:31)
    at C:\Users\saran\AppData\Roaming\npm\node_modules\react-native\node_modules\@react-native-community\cli\build\commands\link\linkAssets.js:42:16
    at Array.forEach (<anonymous>)
    at linkAssets (C:\Users\saran\AppData\Roaming\npm\node_modules\react-native\node_modules\@react-native-community\cli\build\commands\link\linkAssets.js:33:32)
    at linkAll (C:\Users\saran\AppData\Roaming\npm\node_modules\react-native\node_modules\@react-native-community\cli\build\commands\link\linkAll.js:96:31)
    at Object.link [as func] (C:\Users\saran\AppData\Roaming\npm\node_modules\react-native\node_modules\@react-native-community\cli\build\commands\link\link.js:82:33)
    at Command.handleAction (C:\Users\saran\AppData\Roaming\npm\node_modules\react-native\node_modules\@react-native-community\cli\build\index.js:186:23)
    at Command.listener (C:\Users\saran\AppData\Roaming\npm\node_modules\react-native\node_modules\commander\index.js:315:8)
    at Command.emit (events.js:315:20)
    at Command.parseArgs (C:\Users\saran\AppData\Roaming\npm\node_modules\react-native\node_modules\commander\index.js:651:12)
info Run CLI with --verbose flag for more details.

因为此自定义字体不适用于文本。我正在使用“反应”:“17.0.1” “反应本机”:“0.64.2”。 这是我的 android/build.gradle 文件

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext {
        buildToolsVersion = "29.0.3"
        minSdkVersion = 21
        compileSdkVersion = 30
        targetSdkVersion = 30
        ndkVersion = "20.1.5948944"
        supportLibVersion="28.0.0"
        playServicesVersion="17.0.0"
        androidMapsUtilsVersion="0.6.2"
        googlePlayServicesAuthVersion = "16.0.1" // <--- use this version or newer
        multiDexEnabled=true
    }
    repositories {
        google()
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:3.5.4")
        classpath 'com.google.gms:google-services:4.3.10'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.8.1'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        mavenLocal()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url("$rootDir/../node_modules/react-native/android")
        }
        maven {
            // Android JSC is installed from npm
            url("$rootDir/../node_modules/jsc-android/dist")
        }

        google()
        jcenter()
        maven { url 'https://www.jitpack.io' }
    }
}

这是我的react-native.config.js 文件

module.exports = {
  project: {
    ios: {},
    android: {},
  },
  dependencies: {
    '@react-native-google-signin/google-signin': {
      platforms: {
        ios: null,
      },
    },
    'react-native-fbsdk-next': {
      platforms: {
        ios: null,
      },
    },
  },
  assets: ['./src/assets/fonts'],
};

和 package.json

  "rnpm": {
    "assets": "./src/assets/fonts"
  } 

I am trying to apply custom fonts to my react native application. When i run this command

react-native link or yarn react-native link

It gives me the following error when I try to link custom fonts to my app

info Linking assets to ios project
error Linking assets failed.
TypeError: Cannot read property 'UIAppFonts' of null
    at Object.linkAssetsIOS [as copyAssets] (C:\Users\saran\Documents\GitHub\estate-92-mobile\node_modules\@react-native-community\cli-platform-ios\build\link\copyAssets.js:89:31)
    at C:\Users\saran\AppData\Roaming\npm\node_modules\react-native\node_modules\@react-native-community\cli\build\commands\link\linkAssets.js:42:16
    at Array.forEach (<anonymous>)
    at linkAssets (C:\Users\saran\AppData\Roaming\npm\node_modules\react-native\node_modules\@react-native-community\cli\build\commands\link\linkAssets.js:33:32)
    at linkAll (C:\Users\saran\AppData\Roaming\npm\node_modules\react-native\node_modules\@react-native-community\cli\build\commands\link\linkAll.js:96:31)
    at Object.link [as func] (C:\Users\saran\AppData\Roaming\npm\node_modules\react-native\node_modules\@react-native-community\cli\build\commands\link\link.js:82:33)
    at Command.handleAction (C:\Users\saran\AppData\Roaming\npm\node_modules\react-native\node_modules\@react-native-community\cli\build\index.js:186:23)
    at Command.listener (C:\Users\saran\AppData\Roaming\npm\node_modules\react-native\node_modules\commander\index.js:315:8)
    at Command.emit (events.js:315:20)
    at Command.parseArgs (C:\Users\saran\AppData\Roaming\npm\node_modules\react-native\node_modules\commander\index.js:651:12)
info Run CLI with --verbose flag for more details.

Due this custom fonts are not applying to text. I am using "react": "17.0.1"
"react-native": "0.64.2".
Here is my android/build.gradle file

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext {
        buildToolsVersion = "29.0.3"
        minSdkVersion = 21
        compileSdkVersion = 30
        targetSdkVersion = 30
        ndkVersion = "20.1.5948944"
        supportLibVersion="28.0.0"
        playServicesVersion="17.0.0"
        androidMapsUtilsVersion="0.6.2"
        googlePlayServicesAuthVersion = "16.0.1" // <--- use this version or newer
        multiDexEnabled=true
    }
    repositories {
        google()
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:3.5.4")
        classpath 'com.google.gms:google-services:4.3.10'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.8.1'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        mavenLocal()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url("$rootDir/../node_modules/react-native/android")
        }
        maven {
            // Android JSC is installed from npm
            url("$rootDir/../node_modules/jsc-android/dist")
        }

        google()
        jcenter()
        maven { url 'https://www.jitpack.io' }
    }
}

Here is my react-native.config.js file

module.exports = {
  project: {
    ios: {},
    android: {},
  },
  dependencies: {
    '@react-native-google-signin/google-signin': {
      platforms: {
        ios: null,
      },
    },
    'react-native-fbsdk-next': {
      platforms: {
        ios: null,
      },
    },
  },
  assets: ['./src/assets/fonts'],
};

and package.json

  "rnpm": {
    "assets": "./src/assets/fonts"
  } 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

堇年纸鸢 2025-01-20 23:13:45

就我而言,我删除项目中的 ios 文件夹,然后使用以下命令重新创建

react-native eject

,然后运行 ​​react-native link

in my case i delete ios folder in my project and then recreate with following command

react-native eject

then i run react-native link

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文