Unity Jar Resolver

 Many Unity plugins have dependencies upon Android specific libraries, iOS CocoaPods, and sometimes have transitive dependencies upon other Unity plugins. This causes the following problems:

  • Integrating platform specific (e.g Android and iOS) libraries within a Unity project can be complex and a burden on a Unity plugin maintainer.
  • The process of resolving conflicting dependencies on platform-specific libraries is pushed to the developer attempting to use a Unity plugin. The developer trying to use your plugin is very likely to give up when faced with Android or iOS-specific build errors.
  • The process of resolving conflicting Unity plugins (due to shared Unity plugin components) is pushed to the developer attempting to use your Unity plugin. In an effort to resolve conflicts, the developer will very likely attempt to resolve problems by deleting random files in your plugin, report bugs when that doesn't work and finally give up.

The Play Services Resolver plugin (the name comes from its origin of just handling Google Play Services dependencies on Android) provides solutions for each of these problems.

Get the latest unity-jar-resolver here.

Using With Android Native

Android Native is shipped with all required libraries inside. We should also say that all those libraries will remain disabled until you enable the API  that requires a specific library to be installed as part of a build.

Long story short, you do not have to use the Unity jar resolver with Android Native plugin. However, from the previous chapter, you already understand how convenient it may be for the unity android development in general. 

Once you enabled jar resolver support inside the Android Native plugin setting it will uninstall all libraries it shipped with and will only generate dependencies for the jar resolver to resolve. The generate dependencies are located inside the AN_Dependencies.xml file if any. Otherwise, the dependencies file will not be created at all.

If you are ready to use Jar Resolver open the Android Native Settings page and scroll down to the resolver options. If you do not have resolver installed in your project, you will see the following menu:

1. Download. Use the download button to download and install the latest jar resolver version into your project.

2. Refresh. There is no straight forward mechanism the playing may use to detect that you already have the resolver in your project, so if you are sure that jar resolver already exists in your project but you still see the download button, git the refresh button ot help plugin to detect the resolver.

Once resolver is installed you will have the following menu:

1. Restart Resolver.  Will restart the Android resolver.  This button would do the same as restarting the resolver from its context menu. It is there just for your convenience. 

2. Regenerate. The Dependencies are only re-generated during the build pre-process stage. When you change different menu option plugin will not reconfigure a project and builds settings, reconfiguration will only happen during the build pre-process stage. This mean that resolver may or may not have enough time to get all the libraries ready for you. As a result firest build may fail. If you want to make sure that plugin configuration is up to date, just git the Regenerate button.

3. Open. You may open generated AN_Dependencies.xml file with this button.


Known Issues

The jar resolver is the third-party solution under a MIT license. So if you going to use it, you should be aware of it. I will be adding here user reports/solutions due to using Jar resolver in the project. 

Xcode Linker error 

Resolver generates an *.xcworkspace project file for XCode, if you'll use the default project file, you will get a linker error.

Multiple Dex Files Error 

This is one of most common error developers will face when building for Android and having multiple 3-rd party plugins installed int a project. The error description will give you the name of the duplicated library or program.

The error would look similar to :

D8: Program type already present: <lib_name>

Unfortunately, I can't give guidelines on how to avoid or how to solve it since it is completely unrelated to Stan's Assets plugins. However, in most cases, it can be solver fairly simple when using a jar resolver.

Analyze Assets/Plugins/Android folder content. 

The folder will contain *.aar files and it also may contain lib project - I personally do not recommend to keep lib project under that folder since it creates confusion. But you can't always control the way external plugins are placing the resources. 

To give you an idea, here is how the lib project would look like 

Your goal is to determine if this lib project is really necessary. For example, in this case, I can say that Firebase lib project is required since it will contain my project settings inside.

Try to remove everything from that folder except things that aren't just simple libraries. Then run Force Resolve

If that will not help, try to locate duplicates in your project. For example, If you already have aar lib inside that folder with name: com.android.support.support-v4-27.1.1

Make sure that there is no other Android support aar, jar or library it not necessarily will be named the same way, could be something like com.android.support.support-v4, support-v4, android_support_v4, etc.

I hope this small section will help you successfully resolve your Dex issue.