Unity构建首个Android项目失败:资源重打包错误求助
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 Settingsand set aTarget API Levelthat 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:
- In Unity, go to
Player Settings > Android > Publishing Settings, checkCustom Main Manifestto enable editing the manifest file - Open the generated AndroidManifest.xml (usually in
Assets/Plugins/Android) - Find the
<application>tag'sandroid:themeattribute, change@style/UnityThemeSelectorto a system-built theme like:
or for newer SDKs:android:theme="@android:style/Theme.Holo.Light"android:theme="@android:style/Theme.Material.Light" - 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
TempandLibraryfolders - 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 Supportis checked, along with the requiredAndroid 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




