Cordova构建应用报错:找不到android:font等FontFamilyFont属性
Hey there, I’ve dealt with this exact headache when building Cordova Android apps before—those FontFamilyFont attribute errors almost always stem from mismatched Android SDK versions or outdated Cordova platform/plugin configurations. Let’s break down the proven fixes that got me back on track:
1. Update Your Cordova Android Platform
The android:font, android:fontStyle, and android:fontWeight attributes were introduced in Android API 26 (Android 8.0). If your Cordova Android platform is too old, it won’t recognize these attributes.
- First, check your current platform version:
cordova platform ls - If you’re running a version older than
cordova-android@8.0.0(the first version supporting API 26), update to the latest stable release:cordova platform remove android cordova platform add android@latest - You can also specify a specific compatible version (e.g.,
cordova-android@11.0.0) if your project has dependencies that require it.
2. Align Your Android SDK Versions
Make sure your project targets a sufficiently high Android SDK version. Instead of editing the auto-generated build.gradle directly (Cordova might overwrite it), configure this via config.xml:
- Open your project’s
config.xml, find the<platform name="android">section, and add these preferences:
Use the latest stable SDK version (you can check Android’s official docs for current recommendations).<preference name="android-compileSdkVersion" value="33" /> <preference name="android-targetSdkVersion" value="33" />
3. Clean Up Build Caches
Stale build files often cause weird, unexplained errors. Wipe the cache and rebuild:
cordova clean android rm -rf platforms/android/build rm -rf platforms/android/app/build cordova build android
4. Update or Troubleshoot Plugins
Outdated third-party plugins might rely on old Android SDK versions, creating conflicts:
- List all installed plugins to check for updates:
cordova plugin ls - Update individual plugins to their latest versions:
cordova plugin update <plugin-name> - If a specific plugin seems to be the culprit, try removing and re-adding it:
cordova plugin remove <plugin-name> cordova plugin add <plugin-name>@latest
These steps should resolve the FontFamilyFont attribute errors for most cases. If you’re still stuck, double-check that you have the required SDK versions and build tools installed in your Android SDK Manager.
内容的提问来源于stack exchange,提问作者George Stoilov

