我想你没有办法做到这一点(可能在那里,但还没有看到它),因为这种类型的必需Java包装,所以我想使用另一个解决方案,使用Java作为你的C#调用,然后你可以这个调用从。NDK calls
intermediate
redirect
NDK code
java
using UnityEngine;
using System.Collections;
using System.IO;
#if UNITY_ANDROID
public class JavaCallPlugin {
// Avoid invalid calls
public static void initiateNDK() {
if (Application.platform != RuntimePlatform.Android)
return;
var pluginClass =
new AndroidJavaClass("com.package.class.UnityJavaDelegate");
AndroidJavaObject plugin =
pluginClass.CallStatic<AndroidJavaObject>("obj");
return plugin.Call("javaCallToNDK");
}
}
#endif
在你的java文件中这样做
package com.package.class;
import android.content.ContentValues;
import android.content.Intent;
import android.os.Environment;
public class UnityJavaDelegate{
private static UnityJavaDelegate obj;
// define function call to your NDK method with native keyword
private native void api_initialize();
static {
System.loadLibrary("yourlibraryname"); // setup your ndk lib to use
}
public static UnityJavaDelegate getObj() {
if(m_instance == null)
obj= new UnityJavaDelegate();
return obj;
}
private UnityJavaDelegate(){
}
public void javaCallToNDK(){
// this call may not work because i haven't passed class
// loader TO NDK before, if not then you should try links
// at the bottom of the post to know how to pass customize
// as parameter to NDK.
// put your call to NDK function here
api_initialize(this.getClass().getClassLoader());
}
}
当你声明本机方法时,会自动生成一个ndk调用定义,javaEnv和jobject作为参数,所以我想你只需要在这里传递类加载器。您可以尝试此链接和此链接,以防万一。javah
祝你好运,希望这会有所帮助。