- Home /
Can I get a list of methods for a class with JNI?
I'm interfacing with the Android SDK and currently trying to call MediaCodec.getInputBuffer(int). I'm getting an error that the method/signature doesn't exist though;
AndroidJavaObject InputByteBuffer = Codec.Call<AndroidJavaObject> ("getInputBuffer", BufferIndex);
My Codec class is fine (dequeBufferIndex gave me a valid index), but when I execute this line I get
Exception:
java.lang.NoSuchMethodError: no methid with name='getInputBuffer' signature='(i)Ljava/lang/Object;' in class Landoird/media/MediaCodec;
So, I'm presuming this function exists, but maybe I need to re-interpret ByteBuffer as a different type?... or perhaps call it manually with an explicit signature...
So what would really help is a way of seeing all the methods on a Java class... isthis possible?
Hey @SoylentGraham,
Did you ever have any luck interfacing with the mediaCodec? I'm working on a project atm and would value your insight.
Yes, but mostly through the ND$$anonymous$$ (in a c++ plugin with JNI). I'm far far more educated in JNI now :) Feel free to send me a message, email, tweet etc if you need help with something
Answer by Bunny83 · Dec 19, 2014 at 07:31 PM
Unity nor JNI provides any reflection interface. However, Java itself has reflection support. Though using Javas' reflection via JNI would probably be a pain. Also using reflection most likely wouldn't tell you more than the Android API documentaion can tell you. So getInputBuffer does exist and the signature should be:
(I)Ljava/lang/Object;
I don't know why your signature has a lowercase "i" as parameter type. I'm not even sure if it makes a difference. What type has your BufferIndex variable? Unity's JNI wrapper detects and generates the signature based on what you pass to the method.
It was actually a capital i, couldn't copy & paste the error at the time
I verified the signature by calling this (in OSX ter$$anonymous$$al)
javap -classpath android.jar -s android.media.$$anonymous$$ediaCodec
which is in fact
(I)Ljava/nio/ByteBuffer;
But this didn't work either. I got the android API value at runtime to check it was up to date (19), but still refused to work.... strange.... never quite figured it out and just used the deprecated getInputBuffers
(I)Ljava/lang/Object; should already be a valid signature since ByteBuffer is, like all objects, derived from Object. Unity uses Object for any class derived from Object. Can you post a bit more of your code? Especially how you get / create the instance of the $$anonymous$$ediaCodec class.
ah, I assumed the signature must be precise (this is my first time using JNI :) All the code is up here https://github.com/SoylentGraham/UnityAndroidVideoTexture/blob/master/Assets/$$anonymous$$ediaCodec.cs Though I've mostly abandoned this now (using the low level GL stuff is a pain with the external texture type) and just using a c++ plugin ins$$anonymous$$d. Though it would have been nice to get it working without a plugin.
Answer by SoylentGraham · Jun 11, 2015 at 06:43 PM
Revisiting my own answer... don't forget
cd $ANDROID_HOME/platforms/android-19
first, otherwise it won't find any classes
Your answer

Follow this Question
Related Questions
Getting native Android String constants via JNI broken in Unity 2019.2.0? 3 Answers
Getting byte[] or ByteBuffer[] from native Java 1 Answer
Passing AndroidJavaObject to C++ method using JNI 0 Answers
What is the difference between AndroidJavaClass.Call and AndroidJavaObject.Call 2 Answers
JNI - local reference table overflow 0 Answers