0

我正在使用android java插件来统一调用我的java函数,如下所示:

static IntPtr cls_Activity;
static IntPtr fid_Activity;
static IntPtr obj_Activity;
static IntPtr kdataActivityClass;
static IntPtr startAdsMethod;

    void Start () {
        cls_Activity = AndroidJNI.FindClass("com/unity3d/player/UnityPlayer");
        fid_Activity = AndroidJNI.GetStaticFieldID(cls_Activity, "currentActivity", "Landroid/app/Activity;");
        obj_Activity = AndroidJNI.GetStaticObjectField(cls_Activity, fid_Activity);
        kdataActivityClass = AndroidJNI.FindClass("com/kdata/unitytest/UnityUrlPlugin");
        startAdsMethod = AndroidJNI.GetMethodID(PakdataActivityClass, "getURL","()V");
        Debug.Log("obj_Activity"+obj_Activity);     
        Debug.Log("kdataActivityClass"+kdataActivityClass);     
        Debug.Log("Method"+startAdsMethod);     
            if (AndroidJNI.IsInstanceOf(obj_Activity, kdataActivityClass) != false)
            {                 
               jvalue[] myArray = new jvalue[1];
               AndroidJNI.CallStaticStringMethod(obj_Activity, startAdsMethod, myArray);
            }

问题是我正在访问该类,但该类的方法返回 null

Debug.Log("obj_Activity"+obj_Activity);=>retuns value Debug.Log("kdataActivityClass"+kdataActivityClass);=>returns =>value
Debug.Log("Method"+startAdsMethod);=>retunns null <=== 这是这个方法的问题

应该返回一个硬编码的字符串,但它不能统一工作。

高度赞赏帮助。谢谢

4

1 回答 1

0

使用 javap 检查 getURL 方法 jni 签名(您是否将相同的内容放入第三个参数?):

cd <pathToUnityUrlPluginClass>

javap -p -s <UnityUrlPlugin>
于 2012-06-05T11:39:19.057 回答