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:
- In your Android Studio project, create an Android Library module: File > New > New Module > Android Library
- make sure your minSdkVersion and targetSdkVersion match your Unity project setup
- Add your classes etc to the module and build
- A successful build should create a .aar file in build/outputs/aar/ e.g. my module creates mkunityplugin-release.aar
- Open your Unity project, then drag the .aar file directly onto Assets/Plugins/Android in your Project view. This creates an asset which you can view in the inspector; it will show info on the plugin and the Android platform should be checked
- Build your Unity project for Android. My first attempt failed because I had a different targetSdkVersion so I got a build error saying the manifests could not be merged; I fixed that in my Android Studio build.gradle and then it worked
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/