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.
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:
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:
|- com.google.android.gms (NB: was "google-play-services_lib")
|- com.google.example.games.basegameutils (NB: was "BaseGameUtils")
|- com.google.example.games.pluginsupport (NB: "MainLibProj")
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).
As an aside, I found reference to the fact that subfolders are not supported as of this writing (November, 2014) for iOS (see: http://docs.unity3d.com/Manual/PluginsForIOS.html), but there is no mention of such a limitation in the current Android documentation.
Answer by Yury-Habets
Nov 21, 2014 at 08:53 PM
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 http://docs.unity3d.com/Manual/PluginsForAndroid.html 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
line. Try adding it... Though you would probably also need some magic with the manifests, but the classes should be present now.
Ah! I think you're right! Let me try the android.library property. I forgot completely about that! I actually think I may have made a change to that property haphazardly before. Do you happen to know where (if at all) that property is documented? I couldn't find it.
Thanks Yury, that was exactly the issue that I was experiencing. Both in the case that one of my subfolders had a project.properties with android.library=false and another didn't have one at all.
Also, in case anyone is interested it appears .jar files in the root of Plugins/Android will be staged under the StagingArea/plugins directory, whereas subfolders identified by android.library=true in the project.properties files will be staged under StagingArea/android-libraries.
Answer by Bunny83
Nov 21, 2014 at 03:48 PM
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.
Thanks @Bunny83! Always to the rescue. That is what I'm lead to believe, based on my personal experiences. It appears that AndroidManifest.xml files may be read from subfolders, but I need to test a bit with it. You don't happen to know of any example of the "preferred Android setup", with jars, resources, etc. do you?
Answer by psycocrusher
Nov 21, 2014 at 06:47 PM
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:
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
30 People are following this question.
I need add .jar project Unity
How to package resources which are in a Jar file
Any resource for creating jar without extending UnityActivityPlayer?
Integrating .jar file with unity
How to: Android + Jar