Unity中使用One Signal/Pushwoosh推送插件时Gradle构建失败求助
Hey there, let's work through this Gradle build failure you're hitting when using OneSignal and Pushwoosh push notification plugins in Unity. That android:font attribute error in FontFamilyFont is usually linked to mismatched Android tooling versions or plugin dependency conflicts—here are actionable steps to resolve it:
Step 1: Update Android SDK Build Tools
The android:font attribute was introduced in Android 8.0 (API level 26), so older Build Tools versions won't recognize it.
- Open Unity Editor → Go to Edit > Project Settings > Player
- Switch to the Android tab, scroll to Publishing Settings
- Under Build Tools Version, select a version 26.0.0 or higher (e.g., 28.0.3 or the latest compatible version)
Step 2: Upgrade Gradle Version
Unity's default Gradle version might be too old to support newer Android attributes.
- In the same Android Player settings, scroll to the Gradle section
- Set Gradle Version to 5.6.4 or higher (6.x versions work well too, just ensure compatibility with your chosen Build Tools)
- Alternatively, manually edit the
gradle-wrapper.propertiesfile in your project'sAssets/Plugins/Androidfolder, update thedistributionUrlto a recent Gradle release:distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip
Step 3: Resolve Plugin Dependency Conflicts
OneSignal and Pushwoosh might be pulling in conflicting Android support libraries or font-related dependencies:
- Navigate to
Assets/Plugins/Androidand check for duplicate.jaror.aarfiles (especially those related to AndroidX or support libraries) — delete any duplicates - Test building with only OneSignal enabled first, then only Pushwoosh. If one works alone, the issue is a dependency conflict between the two. You'll need to align their dependency versions (check each plugin's documentation for recommended Android library versions)
Step 4: Fix Custom Font Family Configs
If you have custom font XML files in res/font (added either manually or by plugins):
- Ensure you're using the correct attribute for your min SDK version:
- For API 26+,
android:fontis valid - For lower API levels, use
app:fontinstead (requires the AndroidX AppCompat library)
- For API 26+,
- Double-check that your project's Minimum API Level (in Player Settings) matches the attributes you're using
Step 5: Clear Caches
Stale caches often cause weird build issues:
- In Unity, go to File > Build Settings > Android and click Clean Build Folder
- Manually delete the Gradle cache folder at
C:\Users\[YourUsername]\.gradle\caches, then restart Unity and rebuild
Your Original Error Log:
CommandInvokationFailure: Gradle build failed.
C:/Program Files (x86)/Java/jdk1.8.0_77\bin\java.exe -classpath "C:\Program Files\Unity\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle\lib\gradle-launcher-4.0.1.jar" org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx1024m" "assembleRelease"
stderr[ ERROR: In FontFamilyFont, unable to find attribute android:font ERROR: In FontFamilyFont, unable to fin...
内容的提问来源于stack exchange,提问作者Junaid Pathan

