【发布时间】:2021-05-23 12:07:04
【问题描述】:
我正在尝试将表面从片段传递到我的本机代码。
但是当我使用 ANativeWindow_fromSurface(env,surface); 创建时,ANativeWindow 始终为空
我使用的是 kotlin 而不是 java。
我从片段中的 onViewCreated() 函数调用本机函数:
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
surfaceView = view.findViewById(R.id.surfaceView)
surface = surfaceView.holder.surface
myClass = MyClass()
myClass.myFunction(surface)
}
我的班级:
class MyClass{
init {
System.loadLibrary("nativeLib")
}
external fun myFunction(surface: Surface): Int
}
这是我的 native.cpp :
extern "C"
JNIEXPORT jint JNICALL
Java_com_my_app_MyClass_myFunction(JNIEnv *env,jobject obj,jobject surface){
nativeWindow = ANativeWindow_fromSurface(env,surface);
if(nativeWindow == nullptr){
ALOG("nativeWindow is null");
return -1;
}
}
当我安装我的应用程序时,它显示 nativeWindow 为空。 为什么它是空的? 谁能建议我解决这个问题?
【问题讨论】:
标签: android c android-ndk java-native-interface surfaceview