Unity Error: Unable to convert classes into dex format

后端 未结 1 805
既然无缘
既然无缘 2021-01-06 05:16

I have created an Android Unity plugin (.aar file) which provides some custom positioning data to my Unity game. In my Unity script, I use,

var x = customClass

相关标签:
1条回答
  • 2021-01-06 06:04

    The classes.jar (which you later renamed it to 'unity_classes.jar') gets automatically included into the built .apk by Unity, so you shouldn't include it yourself again (in your Android plugin), even under a different name.

    In other words, first your android plugin "embeds" this .jar file inside itself. Then, when Unity adds your plugin into the game project, it also adds its own copy of that .jar file (it does that for all android projects). Consequently, Unity essentially ends up having 2 copies of the same .jar file in the project and complains by saying 'unable to convert classes into dex format'.

    So although you have to use this library (.jar file) in your project but you should not bundle this library with your project. How to do that? If you're using Android studio, you can achieve this by marking the .jar file as a dependency with the provided scope.

    To do this, you can:

    1) Go to 'build.gradle' of your module and change this:

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

    to this:

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

    Or

    2) you can right-click on the module (in Android pane) and choose Open Module Settings. Then go to Dependencies tab. Find the Unity module (which I renamed it to unity_classes.jar) and change its scope to Provided.

    0 讨论(0)
提交回复
热议问题