I'm trying to create AR session by ARCore C library inside a NativeActivity. However, the function "ArSession_create()" always returns error code AR_ERROR_FATAL (-2), but there is no crash expcet that the AR session is not created. The following is the code snippet:
// Get the Android activity by a global variable, which is recorded
// in the NDK glue library function "void ANativeActivity_onCreate()"
// by the function's first passed-in parameter
ANativeActivity* activity = _global_android_activity;
//Get the JNI Env for the current thread
JNIEnv* env = NULL;
JavaVM* vm = activity->vm;
int r = vm->AttachCurrentThread(&env, NULL);
//Create AR session
ArSession* arSession = nullptr;
ArStatus status = ArSession_create(env, activity->clazz, &arSession);
if (status != ArStatus::AR_SUCCESS)
CONSOLE_PRINTF(L"@@@@@@@@@@@@@@@ Failed to create AR session!, Result = %d", status);
else
CONSOLE_PRINTF(L"@@@@@@@@@@@@@@@ Succeeded to create AR session!");
Android Logcat error message:
04-12 22:06:10.084 24454-24473/com.omnigsoft.gameenginedemo E/third_party/redwood/base/jni_common/src/class_util.cc: Failed to find class com/google/ar/core/SessionCreateJniHelper using custom class loader.
04-12 22:06:10.085 24454-24473/com.omnigsoft.gameenginedemo E/third_party/arcore/ar/core/android/sdk/session_create.cc: Failed to load SessionCreateJniHelper class.
I have confirmed that I have done the following thing to enable AR for my Android native app in the AndroidManifest.xml file:
- minSdkVersion set to 24
- added permission "android.permission.CAMERA"
- added ARCore meta data: android:name="com.google.ar.core"
I also have confirmed that my device (Google Pixel XL) is able to run ARCore sample app "hello_ar_c" (from the ARCode SDK, built by Android Studio).
So the question is: why the function ArSession_create() fails? Has anyone successfully use ARCode C library with NativeActivity? Thanks for any suggestions.