TypeError: Cannot read property 'UIAppFonts' of null while linking custom fonts with react native project
TypeError: Cannot read property 'UIAppFonts' of null while linking custom fonts with react native project
我正在尝试将自定义字体应用于我的 React 本机应用程序。当我运行这个命令
react-native link or yarn react-native link
当我尝试 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' }
}
}
这是我的反应-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"
}
在我的例子中,我删除了项目中的 ios 文件夹,然后使用以下命令重新创建
react-native eject
然后我运行react-native link
我正在尝试将自定义字体应用于我的 React 本机应用程序。当我运行这个命令
react-native link or yarn react-native link
当我尝试 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' }
}
}
这是我的反应-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"
}
在我的例子中,我删除了项目中的 ios 文件夹,然后使用以下命令重新创建
react-native eject
然后我运行react-native link