本文介绍了Unity3D和AAR问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须为Unity3D构建一个aar模块,但是这样做有很多问题.

I have to build an aar module for Unity3D, but there are too many issues to do so.

我的工作环境

我建立了一个aar文件并将其解压缩以删除libs中的classes.jar,然后将aar文件和AndroidManifest.xml复制到 asset \ Plugins \ Android . android项目和unity项目的程序包名称相同.

I have built an aar file and unziped it to removed the classes.jar in libs, afterwards I copied the aar file and AndroidManifest.xml to asset\Plugins\Android. The package name of both, the android project and the unity project, are the same.

此后生成APK文件,导致以下异常:

Building the APK File afterwards, resulted in the following exception:

IOException: Failed to Move File / Directory from 'Temp/StagingArea/android-libraries/app-debug/classes.jar' to 'Temp/StagingArea/android-libraries/app-debug/libs/classes.jar'.
UnityEditor.Android.PostProcessor.Tasks.ProcessAAR.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context)
UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context)
UnityEditor.Android.PostProcessAndroidPlayer.PostProcess (BuildTarget target, System.String stagingAreaData, System.String stagingArea, System.String playerPackage, System.String installPath, System.String companyName, System.String productName, BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry)
UnityEditor.Android.AndroidBuildPostprocessor.PostProcess (BuildPostProcessArgs args)
UnityEditor.PostprocessBuildPlayer.Postprocess (BuildTargetGroup targetGroup, BuildTarget target, System.String installPath, System.String companyName, System.String productName, Int32 width, Int32 height, System.String downloadWebplayerUrl, System.String manualDownloadWebplayerUrl, BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry, UnityEditor.BuildReporting.BuildReport report) (at /Users/builduser/buildslave/unity/build/Editor/Mono/BuildPipeline/PostprocessBuildPlayer.cs:186)
UnityEditor.HostView:OnGUI()

我一直在寻找答案3天,我已经尝试了所有在网上找到的内容,请帮忙!

I've been looking for an answer for 3 days and I've tried everything I have found online, please help!

我很确定aar文件libs文件夹中没有任何内容

I'm pretty sure there is nothing inside the aar files libs folder

推荐答案

从Android Studio查找您的 Build.gradle 文件,查找捆绑 classes.jar 文件.

Find your Build.gradle file from Android Studio, look for any command that bundles the classes.jar file.

取决于您的Android Studio项目的生成方式,它应如下所示:

Depending on how your Android Studio project is generated, it should look like this:

compile files('libs/jars/classes.jar')

compile fileTree(dir: 'libs', include: ['*.jar'])


只需将"compile"替换为"provided"关键字


Just replace the "compile" with "provided" keyword

provided files('libs/jars/classes.jar')

provided fileTree(dir: 'libs', include: ['*.jar'])

这将使Android Studio从最终的arr插件版本中排除.jar插件.现在,您可以再次构建插件并将其传输到Assets/Plugins/Android文件夹中.我建议您使用一个新项目来执行此操作,以确保在任何地方都没有重复项.

This will make Android Studio exclude the .jar plugin from the final arr plugin build. You can now build the plugin again and transfer it into the Assets/Plugins/Android folder. I suggest you do so with a new project to make sure there is no duplicate anywhere.

您还可以通过右键单击 classes.jar 插件并将其设置为已提供进入模块设置. 依赖关系标签.

You can also go the Module Settings by right-clicking on the classes.jar plugin-in and set it to Provided in the Dependencies tab.

注意:

您无需手动将 AndroidManifest.xml 文件添加到Unity项目中,因为如果这是 arr 插件,这将由Unity自动完成.如果这是一个 jar 插件,则只需要这样做.不过,如果仍然遇到权限问题,请手动执行.

You don't need to manually add the AndroidManifest.xml file to the Unity project because this will automatically be done by Unity if this is an arr plugin. You only need to do so if this is a jar plugin. Although, if you still run into permission problems then do that manually.

这篇关于Unity3D和AAR问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 12:24