Where can .jar files be placed under Assets/Plugins/Android?

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).

We support the following Android plugin types:

  • plain compiled .jar files - can be placed in Assets/Plugins/Android, Assets/Plugins/Android/bin and Assets/Plugins/Android/libs. They are copied to StagingArea and compiled into resulting .dex. No resource or manifest merging available here (only complete overriding the manifest by placing it into Assets/Plugins/Android/AndroidManifest.xml)
  • Android library projects - this is a subdir in Assets/Plugins/Android with its own project structure (just as you described in the original post). The compiled .jar file can be placed in libs/ or bin/, resources and manifests are merged. Please refer to Android Library Project section in Unity - Manual: Create and use plug-ins in Android for more details.

My wild guess is that your subdirs are not being identified as Android Library projects because the project.properties file does not contain

android.library=true 

line. Try adding it… Though you would probably also need some magic with the manifests, but the classes should be present now.

I’m sure I’ve read it in the manual (though i can’t find it anymore) that subfolders aren’t supported for the Assets/Plugins/Android/ folder. So you should place your .jar file directly into that folder.

You drop them in Asset/Plugins/Android in the same place the AndroidManifest is.

But i got a Plugin from Prime31 and they place it in:

Asset/Plugins/Android/google-play-services_lib/libs/google-play-services.jar