Use Android Libraries to reuse components across multiple applications, or build variations of one app with the same core components. Android Libraries compile into Android Archive (AAR) files that can be used as a dependency for an Android app module.
Android Archive (AAR) plug-ins are bundles that include compiled Java and native (C/C++) code, resources, and an Android Manifest. The .aar file itself is a .zip archive which contains all of the Assets. For more details, see Android Developer documentation on creating an Android Library.
To add an AAR plug-in to your Project, copy the .aar file into any of your Project folders, then select it in Unity to open the Import Settings in the Inspector window. Enable the Android checkbox to mark this .aar file as compatible with Unity:
Android Library projects are similar to AAR plug-ins: they contain native and Java code, resources, and an Android Manifest. However, an Android Library is not a single archive file, but a directory with a special structure which contains all of the Assets. The easiest way to create an Android Library project is by creating a project of this type in Android Studio. For more details, see Android Developer documentation on creating an Android Library.
Android Library projects must have the .androidlib extension for Unity to support them. Add this extension to your library’s root folder name (for example, mylibrary.androidlib
), and place the folder in the Assets
folder of your Unity Project. Unity automatically includes all Android Libraries into the final Gradle project, and build them together with it, in the same way that Android Studio projects are built when they have multiple subprojects.
For more details, see Android Studio documentation on the Library module.
If you need to add Assets to your Unity app that should be copied as they are into the output package, import them into the Assets/Plugins/Android/assets
folder. These will be copied into the assets/
directory of your APK, and you can access them by calling the getAssets()
Android API from your Java code.