Unity构建错误: OBSOLETE – Providing Android resources in Assets/Plugins/Android/res was removed

文章目录

  • 一、背景
  • 二、问题描述
  • 三、解决方案

一、背景

1、项目由Unity 2020.1.33f1升级至Unity 2021.3.9f1

二、问题描述

  1. 错误信息

Exception: OBSOLETE - Providing Android resources in Assets/Plugins/Android/res was removed, please move your resources to an AAR or an Android Library. See “AAR plug-ins and Android Libraries” section of the Manual for more details.
UnityEditor.Android.PostProcessor.Tasks.CheckUserResources.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <5160fdea082d4c479eac116da4ffc2de>:0)
UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <5160fdea082d4c479eac116da4ffc2de>:0)
UnityEditor.Android.PostProcessAndroidPlayer.PrepareForBuild (UnityEditor.BuildOptions options, UnityEditor.BuildTarget target) (at <5160fdea082d4c479eac116da4ffc2de>:0)
UnityEditor.Android.AndroidBuildPostprocessor.PrepareForBuild (UnityEditor.BuildOptions options, UnityEditor.BuildTarget target) (at <5160fdea082d4c479eac116da4ffc2de>:0)
UnityEditor.PostprocessBuildPlayer.PrepareForBuild (UnityEditor.BuildOptions options, UnityEditor.BuildTargetGroup targetGroup, UnityEditor.BuildTarget target) (at <0d6ce211ebbc47e1a35a84c3672ff58f>:0)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

三、解决方案

  1. 原因:

Unity 2021 不再支持直接在Assets/Plugins/Android/res目录下放置Android资源

  1. 解决方法
    (1)Assets/Plugin/Android文件夹下,创建res.androidlib文件夹,并把res文件夹移入res.androidlib下
    (2)创建AndroidManifest.xml文件,添加以下内容,并文件移入res.androidlib文件夹下
<?xml version = "1.0" encoding = "utf-8" ?>
<manifest xmlns:android = "http://schemas.android.com/apk/res/android" package = "custom.android.res" android:versionCode = "1" android:versionName = "1.0" >
</manifest >

在这里插入图片描述