Unity can interpret individual Java and Kotlin source files as individual plug-ins.
Unity supports Java and Kotlin code written in source files with .java
and .kt
extensions. To do this, Unity interprets each source file as an individual plug-in and compiles them when it builds the Player. This type of plug-in is useful if you need to write a small amount of code for a single project. If you plan to reuse the code in multiple projects or distribute it to other people, then an Android Library Projects or Android Archive plug-ins might be more appropriate.
To indicate to Unity to create a plug-in from a Java (.java
) or Kotlin (.kt
) source file:
.java
) or Kotlin (.kt
) source file.Note: You can place the source files in any folder in your Project, except in special use locations such as StreamingAssets. If you place files in these locations, the Unity Editor doesn’t display the plug-in inspector.
By default when you export a Unity project for Android, Unity copies any Java/Kotlin files over to the Android Studio project. If you edit these files in Android Studio, the changes aren’t reflected in the original files in the Unity project. If you export the Unity project again, the export process will overwrite your changes in Android Studio.
To resolve this, Unity provides the Symlink Sources Build Setting. If you select this Build Setting, Unity creates a symbolic link in the Android Studio project to Java/Kotlin files in the Unity project, instead of copying files over. This means that if you edit the files from Android Studio, the edit affects the files in the original Unity project.