Unity supports plug-ins 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 Gradle as your build system.
To compile the source files as a plug-in:
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# scripts with helper classes” section in JAR plug-ins.
2018–11–29 Page amended with editorial review
2018–09–07 Page published with editorial review
Added plug-in support in 2018.2