从 Unity3D C# 脚本中的 AAR 中调用具有多个参数的方法

Calling a method with multiple arguments in AAR from within Unity3D C# script

我通过以下方法获得了 class:

public static int add( int a, int b ){
    return a + b;
}

我正在尝试使用

从 Unity 脚本中调用它
var ajc = new AndroidJavaClass( "com.mil.rfcommunitylib.BluetoothClassic" );
int result = ajc.CallStatic<int,int>( "add", new int[] { 1, 2 } );

但我明白了

AndroidJavaException: java.lang.NoSuchMethodError at my logcat.

怎么了?使用不带参数的方法,因此我们可以假设我正确设置了所有内容。

而不是调用:

var ajc = new AndroidJavaClass( "com.mil.rfcommunitylib.BluetoothClassic" );
int result = ajc.CallStatic<int,int>( "add", new int[] { 1, 2 } );

你应该实际使用:

var ajc = new AndroidJavaClass( "com.mil.rfcommunitylib.BluetoothClassic" );
int result = ajc.CallStatic<int>( "add", 1, 2 );

如果你仔细查看文档:link 你会发现在你的情况下你的函数 returns int 所以它应该是 javaClass.CallStatic<int>(functionName, params ...) ,并且你传递了函数接受的参数作为函数名称后的单独参数,而不是相同参数类型的数组。