对Unity工程进行了大版本升级,从2020.3.20f1升级到2021.3.3f1。
打包报错如下:
Error building Player: 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.
原因
https://docs.unity3d.com/2021.2/Documentation/Manual/UpgradeGuide20212.html
Unity no longer copies Gradle
project assets located in Assets/Plugins/Android/[res, assets] to the Gradle project.
- Previously you could place Gradle resources in this folder and Unity copied them into the Gradle project. You should now use AAR or androidlib plug-ins to pass additional Gradle resources to the application.
- If you place project assets in this folder, Unity shows a build error message.

解决
Step1
查了一下工程中直接目录结构为Plugins/Android/res的有一个,用来存放FCM(FirebaseCloudingMessage)用到的缩略图和颜色值信息。在AndroidManifest.xml文件中有对它们的引用,如下:
<meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@drawable/icon_notification" />
<meta-data android:name="com.google.firebase.messaging.default_notification_color" android:resource="@color/colorNotifyBg" />
另外还有两个目录结构形如:Plugins/Android/XXX/res的,分别是Plugins/Android/FirebaseApp.androidlib/res和Plugins/Android/FirebaseCrashlytics.androidlib/res,这两个目录没有影响。
Step2
经笔者测试,我们工程中只需要对Plugins/Android/res进行处理即可,解决方式就是把Plugins/Android/res下的资源打成aar,再把aar拖拽到Plugins/Android目录下即可。

在将Unity工程从2020.3.20f1升级到2021.3.3f1后,打包时出现错误,提示不再支持在Assets/Plugins/Android/res中提供Android资源。解决方案是将该目录下的资源打包成aar文件,然后将其放入Plugins/Android目录。具体步骤包括检查AndroidManifest.xml中对资源的引用,并将res目录资源移至aar中。完成此操作后,打包错误得以解决。
3530

被折叠的 条评论
为什么被折叠?



