When using Unity3d, "native" (pure-java) Android functionality can be accessed via Plugin. As described in the documentation,
There are several ways to create a Java plugin but the result in each case is that you end up with a .jar file containing the .class files for your plugin
When I create an Android Application Project in eclipse, and set it is a library, it automatically generates a .jar
file in the bin
folder. I understand that this is a temporary file in the context of the Android toolchain, but this is the file that Unity needs in order to see the classes and build up it's own internal JNI magic. (The entire process is outlined very well here in case more clarity is needed on that process.)
Unfortunately, as near as I can tell, Android Studio does not generate this file. Is there a way I can tell it to give me this file, or perhaps some other way to generate code that Unity will be able to use?
During the installation of the Unity Editor, make sure to include the Android Build Support module by checking the box next to it. Expand the Android Build Support module. If you are using Unity 2019 or later, add the Android SDK & NDK Tools module. On the Projects tab, click New to start a new Unity project.
In Unity open File | Build Settings... , check Google Android Project and click Export. Open Android Studio and click Import Project (Eclipse ADT, Gradle, etc.) Within the file selection dialog, navigate to the folder where you exported the project and select the folder named after your app.
With Unity 5.3+ you no longer need to build a .jar, instead you can use the .aar file that is automatically created by an Android Studio Android Library module. I found this a lot easier than getting the jar method to work:
This is where I first heard that .aar could be used directly https://www.reddit.com/r/Unity3D/comments/3eltjz/how_to_add_an_android_library_project_folder_to/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With