CsoundUnity: Loading Plugins on Android

I’m trying to load some Csound plugins on Android, using CsoundUnity.
I’d like to be able to load the plugins from the External Files Dir, called PersistentDataPath on Unity.

So this is the process I’m following now:

  • I have a plugin (scansyn) with “.bytes” extension in a “Unity Resources” folder, which allows me to load the plain bytes from it.
  • I copy the bytes in the above external files dir, and name the file “libscansyn.so” (I checked on device and the file is correctly copied there, and the bytes size is correct)
  • I then create Csound, and set the OPCODE6DIR64 to the above external folder
  • I call the loadPlugins method from the API, that returns 0, and so I assume it correctly executes.
  • When trying to compile a csd which uses the opcode “scanu”, Csound compilation fails

CsoundUnity done init, compiledOk? False

Unexpected untyped word scanu when expecting a variable
Parsing failed due to invalid input!
Stopping on parser failure

Is this even possible?

I also tried only setting the OPCODE6DIR to that path, or either calling LoadPlugins, but with the same result.

So I tried another route, which is adding the plugin together with the other Csound Android libs, and thanks to some Java calls (see below) I retrieved the path of the native libs, and tried to call loadPlugins from that path:

loading plugins from /data/app/~~TU_642OvRLxcjFhD5r5EOA==/com.Csound.Test-346-w_uraBRAXHlIK0FqOQ==/lib/arm64

This correctly loads the plugin and Csound compiles the scanu opcode.
But I’d like to know if the first attempt is really an option, since it would grant me more flexibility on where to put the plugins.

Below the Unity (C#) code to retrieve the native plugins path on Android, maybe it could be useful for others!

public static AndroidJavaObject GetUnityActivity()
    using (var unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
        return unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");

public static AndroidJavaObject GetUnityContext()
    var activity = GetUnityActivity();
    Debug.Log($"activity null? {activity == null}");
    return activity.Call<AndroidJavaObject>("getApplicationContext");

public static AndroidJavaObject GetApplicationInfo()
    var context = GetUnityContext();
    Debug.Log($"context null? {context == null}");
    return GetUnityContext().Call<AndroidJavaObject>("getApplicationInfo");

public static string GetNativeLibraryDir()
    var info = GetApplicationInfo();
    Debug.Log($"info null? {info == null}");
    return info.Get<string>("nativeLibraryDir");