Where should I be placing .jar
files in Unity’s directory structure under Plugins/Android
? Should they be placed in the root-level of this directory, or can they be placed in sub-directories, e.g. Plugins/Android/libs
, Plugins/Android/MyProj/libs
, etc.?
I was looking for documentation on this, and seem to remember seeing some place that Plugins/Android
, Plugins/Android/libs
, and Plugins/Android/bin
were all viable locations, but certain plugin vendors have different directory structures than this.
More Details…
I’ve recently been playing around with a couple of Android plugins (specifically, Google Mobile Ads SDK and Google Play Games) and have been trying to wrap my head around the directory structure for Android-builds.
For instance, Google Play Games creates the following directory structure when it is imported and configured:
Plugins
|- Android
|- BaseGameUtils
|- libs
|- res
|- google-play-services_lib
|- libs
|- res
|- src
|- MainLibProj
|- libs
In the above directory structure, the specific plugin component (e.g. BaseGameUtils
) is collected in its own folder and underneath it has the /libs
, /res
, etc. directories that should contain the appropriate compiled Java classes, resources, etc. that the component relies upon.
Disclaimer: Because I’m a bit neurotic and also like to go against the grain, I modified the directory structure some, because BaseGameUtils
and MainLibProj
meant nothing to me, currently I’ve renamed them such that my directory structure is named after the associated package in the android manifest (e.g. com.google.example.games.basegameutils
), in hindsight these names don’t mean much more to me than their originals, but it serves as a good example of arbitrary folder names:
Plugins
|- Android
|- com.google.android.gms (NB: was "google-play-services_lib")
|- libs
|- res
|- src
|- com.google.example.games.basegameutils (NB: was "BaseGameUtils")
|- libs
|- res
|- com.google.example.games.pluginsupport (NB: "MainLibProj")
|- libs
What I have noticed, and I have yet to test this with the original directory names, is that when I compile and publish a build to an Android device or emulator, the classes referenced in base-game-utils.jar
, under Plugins/Android/com.example.games.basegameutils/libs
are not being found by code that uses them. Furthermore, if I look at the staging area for the project, under Temp/StagingArea/plugins
I don’t see the .jar
files that are present under nested libs
directories in Plugins/Android
.
If I move the jars to the root-level of Plugins/Android
, say for example base-game-utils.jar
I will see this .jar
file referenced under the staging area and it will be found by Unity when resolving class references in Android, rather than giving me a ClassNotFoundException
.
I am currently using one of the 4.6 beta releases (4.6.0b21).