Version: 2018.3 (switch to 2019.1 )
Native (C++) plug-ins for Android
Customizing an Android Splash Screen
Other Versions

Using Java or Kotlin source files as plug-ins

Unity supports plug-insA set of code created outside of Unity that creates functionality in Unity. There are two kinds of plug-ins you can use in Unity: Managed plug-ins (managed .NET assemblies created with tools like Visual Studio) and Native plug-ins (platform-specific native code libraries). More info
See in Glossary
for Android written in Java or Kotlin. This functionality allows you to add .java or .kt files into your Unity Project and they are compiled when you build an Android player. Previously you had to precompile these files as an android library.

Gradle is the only build system that supports this feature so use GradleAn Android build system that automates several build processes. This automation means that many common build errors are less likely to occur. More info
See in Glossary
as your build system.

To compile the source files as a plug-in:

  1. Open the Unity Editor.
  2. Select the Project to add the plug-in to.
  3. In the Projects window, select the AssetsAny media or data that can be used in your game or Project. An asset may come from a file created outside of Unity, such as a 3D model, an audio file or an image. You can also create some asset types in Unity, such as an Animator Controller, an Audio Mixer or a Render Texture. More info
    See in Glossary
    folder and create a folder for your plug-in.
  4. Drag and drop your source files into the folder.
  5. Select each of the files.
  6. In the inspectorA Unity window that displays information about the currently selected GameObject, Asset or Project Settings, alowing you to inspect and edit the values. More info
    See in Glossary
    window, under Select platforms for plugin, verify that only Android is selected.
  7. Build your Project.

Note: You can place your source files in any folder in your Project except in special use locations such as subfolders under Assets/Plugins/Android. If you place files in these locations, the Unity Editor will not display the plug-in inspector. For additional information, see AAR plug-ins and Android Libraries.

Use the AndroidJavaObject class to call methods in your plug-in. For additional information see, the “Using your Java plug-in from C# scriptsA piece of code that allows you to create your own Components, trigger game events, modify Component properties over time and respond to user input in any way you like. More info
See in Glossary
with helper classes” section in JAR plug-ins.


Did you find this page useful? Please give it a rating:

Native (C++) plug-ins for Android
Customizing an Android Splash Screen