You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

Unity构建首个Android项目失败:资源重打包错误求助

解决Unity打包Android时的"@style/UnityThemeSelector"资源缺失错误

Hey there, let's tackle this Android build failure in Unity. The error you're seeing stems from the AndroidManifest.xml referencing a theme that your build setup can't find—@style/UnityThemeSelector. This usually happens due to version mismatches or corrupted project templates. Let's walk through the fixes:

先明确你的报错细节:

CommandInvokationFailure: Failed to re-package resources.
..\tools_r25.2.3-windows\build-tools\27.0.3\aapt.exe package --auto-add-overlay -v -f -m -J "gen" -M "AndroidManifest.xml" -S "res" -I "../tools_r25.2.3-windows\platforms\android-23\android.jar" -F bin/resources.ap_
标准错误输出[ AndroidManifest.xml:4: error: Error: No resource found that matches the given name (at 'theme' with value '@style/UnityThemeSelector').

解决方案1:统一SDK与Build Tools版本

Looking at your error log, you're using Build Tools 27.0.3 with Android SDK 23 (android-23)—these versions are too far apart, which causes resource mismatches.

  • Open Unity, go to Edit > Preferences > External Tools
  • Check the Android SDK path, then head to Player Settings > Android > Other Settings and set a Target API Level that matches your Build Tools version (e.g., set Target API Level to 27 if you're using Build Tools 27.0.3)
  • Alternatively, install Build Tools 23.x to match your android-23 SDK, then select it in Unity's External Tools settings.

解决方案2:替换UnityThemeSelector为系统默认主题

If you need a quick fix without adjusting SDK versions, modify the AndroidManifest.xml directly:

  1. In Unity, go to Player Settings > Android > Publishing Settings, check Custom Main Manifest to enable editing the manifest file
  2. Open the generated AndroidManifest.xml (usually in Assets/Plugins/Android)
  3. Find the <application> tag's android:theme attribute, change @style/UnityThemeSelector to a system-built theme like:
    android:theme="@android:style/Theme.Holo.Light"
    
    or for newer SDKs:
    android:theme="@android:style/Theme.Material.Light"
    
  4. Save the file and try building again.

解决方案3:重建Unity项目缓存与模板

Corrupted temporary files or project templates can also cause this issue:

  • Close Unity completely, along with any open Android Studio instances
  • Navigate to your Unity project folder, delete the Temp and Library folders
  • Reopen Unity—this will force it to regenerate all project resources and Android templates from scratch
  • Once the project finishes loading, attempt the build again.

解决方案4:验证Unity Android组件完整性

Sometimes missing Android build components are the culprit:

  • Open Unity Hub, find the Unity version you're using for this project
  • Click the three-dot menu next to the version, select Add Modules
  • Ensure Android Build Support is checked, along with the required Android SDK & NDK Tools (make sure the SDK version matches what you're using in the project)
  • Install any missing components, restart Unity, and try building.

内容的提问来源于stack exchange,提问作者Meirsho

火山引擎 最新活动