Through this series, I extensively use external links that I encourage you to read. While paraphrased versions of the relevant content will be included here, there may be times when the additional reading will help.
Currently, Unity provides two ways to call native Android code.
To interact with native code, Unity provides some classes and functions.
Note that the first three steps apply ONLY if you wish to have a native plugin!
From here on out, I'll refer to the JAR / AAR file as the native plugin, and the C# script as the C# wrapper
It's immediately obvious that the first way of creating plugins is long drawn, so choosing your route seems moot. However, method 1 is the ONLY way to call custom code. So, how does one choose?
Simply put, does your plugin
Please do NOT try to "mix" (i.e. a part of the plugin using method 1, and the other using method 2) the two methods! While entirely possible, it's often impractical and painful to manage.
Create a new C# script in Unity and replace it's contents with the following
using UnityEngine;
using System.Collections;
public static class UnityAndroidPlugin {
}
Create a new Java class in Android Studio and replace it's contents with the following
package com.axs.unityandroidplugin;
import android.util.Log;
import android.widget.Toast;
import android.app.ActivityManager;
import android.content.Context;
public class UnityAndroidNative {
}
Create a new C# script in Unity and paste these contents
using UnityEngine;
using System.Collections;
public class UnityAndroidPluginGUI : MonoBehaviour {
void OnGUI () {
}
}