Reputation: 3
I am trying to call some java method in OnAudioFilterRead
function body.
Here is the code segment.
void OnAudioFilterRead(float[] data, int channels)
{
AndroidJNI.AttachCurrentThread();
if (ok)
{
if (obj == null)
{
obj = new AndroidJavaObject("com.xx.aop.media.av.GPUFrameCapturer");
Debug.Log(obj.Call<bool>("isRecording"));
}
}
}
When I build apk on Android platform.
Always encountered this error.
06-13 15:20:51.981 20255-20388/com.MeiTu.XRay E/Unity:
AndroidJavaException: java.lang.ClassNotFoundException: Didn't find class "com.unity3d.player.ReflectionHelper" on path: DexPathList[[directory "."], nativeLibraryDirectories=[/system/lib, /vendor/lib, /system/lib, /vendor/lib]]
java.lang.ClassNotFoundException: Didn't find class "com.unity3d.player.ReflectionHelper" on path: DexPathList[[directory "."],nativeLibraryDirectories=[/system/lib, /vendor/lib, /system/lib, /vendor/lib]]
Upvotes: 0
Views: 2334
Reputation: 125255
The OnAudioFilterRead
function is called in another Thread
so it looks like you used AndroidJNI.AttachCurrentThread()
to make it possible to use AndroidJavaObject
from another Thread. You also need to detach it. Call AndroidJNI.DetachCurrentThread()
at the end of the OnAudioFilterRead
function:
void OnAudioFilterRead(float[] data, int channels)
{
AndroidJNI.AttachCurrentThread();
if (ok)
{
if (obj == null)
{
obj = new AndroidJavaObject("com.xx.aop.media.av.GPUFrameCapturer");
Debug.Log(obj.Call<bool>("isRecording"));
}
}
AndroidJNI.DetachCurrentThread()
}
If this doesn't work, initialize the AndroidJavaObject
outside the OnAudioFilterRead
function such as the Start
or Awake
function then use it in the OnAudioFilterRead
function like above.
AndroidJavaObject obj;
void Start()
{
obj = new AndroidJavaObject("com.xx.aop.media.av.GPUFrameCapturer");
}
void OnAudioFilterRead(float[] data, int channels)
{
AndroidJNI.AttachCurrentThread();
if (ok)
{
if (obj == null)
{
Debug.Log(obj.Call<bool>("isRecording"));
}
}
AndroidJNI.DetachCurrentThread()
}
Upvotes: 1