1

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.

Hongkun Wang
  • 717
  • 8
  • 22
  • To confirm: you are not receiving an `ArStatus` that you can inspect? – stkent Apr 13 '18 at 01:59
  • From the code "ArStatus status = ArSession_create(env, activity->clazz, &arSession);", I can say that the fnction returns the value AR_ERROR_FATAL (-2) to status. – Hongkun Wang Apr 13 '18 at 02:24
  • I guess we need to focus on the error message "Failed to find class com/google/ar/core/SessionCreateJniHelper" to find the answer. Anyone has idea about this error message? – Hongkun Wang Apr 13 '18 at 02:26
  • Maybe relevant? Note sure if it applies to your scenario or not. https://github.com/google-ar/arcore-android-sdk/issues/122 – stkent Apr 13 '18 at 02:39
  • Hi stkent, I'm using visual studio 2015 to build my native android app therefore there is no Proguard involved in the building, thank you anyway. – Hongkun Wang Apr 13 '18 at 03:08

2 Answers2

3

Finally I got the reason so I'd like to answer the question by myself.

In order to use ARCore manually in an Android app with other IDE instead of Android Studio, we need to the following things:

  1. Download the ARCore library package (.aar) from Maven repository
  2. Add the ARCore's shared library "libarcore_sdk_c.so" into the app's APK package
  3. Add the ARCore's java library "classes.jar" into the app's APK package

I did 1 and 2 but forgot the 3, therefore I got class-not-found error at run time.

There are more errors come out but at least I solved this problem. It seems like using Android Studio for ARCore app development is the only comfortable way at present.

Hongkun Wang
  • 717
  • 8
  • 22
2

I was also getting this exact error "Failed to find class com/google/ar/core/SessionCreateJniHelper using custom class loader" followed by "Failed to load SessionCreateJniHelper class", when embedding arore-android-sdk/samples/hello_ar_c sample over to the android-ndk/native-activity sample framework (while using Android Studio).

The issue in this scenario was the android:hasCode="false" directive in AndroidManifest.xml that the NativeActivity sample adds. Even if one does not have any Java code in a NativeActivity-based application, linking in ARCore does add Java code, so in that case android:hasCode="false" directive needs to be removed.

trojj
  • 41
  • 1