How to create an object with JNI?

后端 未结 5 1614
孤独总比滥情好
孤独总比滥情好 2020-12-07 18:37

I need to implement some functions into an Android application using NDK and thus JNI.

Here\'s the C code, with my concerns, that I wrote:

#include &         


        
5条回答
  •  感动是毒
    2020-12-07 19:10

    Some problems with your code.

    First, why are you creating your own Point class rather than using library-provided android.graphics.Point?

    Second, the class spec for nested classes is different - it would be "com/example/ndktest/NDKTest$Point". Class nesting is different from packages.

    Third, I don't think JNI lets you create instances of nonstatic nested classes. You need to pass the nesting class object' this pointer at object creation - there's no such argument.

    Finally, while I've seen the guidance to use "void(V)" as a constructor method signature, but this is out of line with the rest of method signatures; normally, a method with two int parameters and void return type would be "(II)V".

    As a side note, I found it much cleaner to pass primitive types and arrays of primitive typed from NDK to Java. Object creation/access is messy and hard to debug.

提交回复
热议问题