Android NDK에서 ARCore 세션 구성
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
ARCore 세션을 구성하여 앱의 AR 환경을 빌드합니다.
세션이란 무엇인가요?
모션 추적과 같은 모든 AR 프로세스는
ARCore 내에서 이루어지는 환경 이해, 조명 추정은
세션입니다. ArSession
는 ARCore로 연결되는 기본 진입점입니다.
API에 액세스할 수 있습니다. AR 시스템 상태를 관리하고 세션 수명 주기를 처리하여
세션을 생성, 구성, 시작 또는 중지합니다. 무엇보다도
앱이 카메라 이미지에 대한 액세스를 허용하는 프레임을 수신하고
있습니다.
세션은 다음 기능을 구성하는 데 사용할 수 있습니다.
ARCore가 설치되어 있고 최신 상태인지 확인
ArSession
를 만들기 전에 ARCore가 설치되어 있고 최신 상태인지 확인합니다.
ARCore가 설치되어 있지 않으면 세션 생성이 실패하고 이후 발생하는 모든 세션
ARCore를 설치하거나 업그레이드하려면 앱을 다시 시작해야 합니다.
/*
* Check if ARCore is currently usable, i.e. whether ARCore is supported and
* up to date.
*/
int32_t is_arcore_supported_and_up_to_date(void* env, void* context) {
ArAvailability availability;
ArCoreApk_checkAvailability(env, context, &availability);
switch (availability) {
case AR_AVAILABILITY_SUPPORTED_INSTALLED:
return true;
case AR_AVAILABILITY_SUPPORTED_APK_TOO_OLD:
case AR_AVAILABILITY_SUPPORTED_NOT_INSTALLED: {
ArInstallStatus install_status;
// ArCoreApk_requestInstall is processed asynchronously.
CHECK(ArCoreApk_requestInstall(env, context, true, &install_status) ==
AR_SUCCESS);
return false;
}
case AR_AVAILABILITY_UNSUPPORTED_DEVICE_NOT_CAPABLE:
// This device is not supported for AR.
return false;
case AR_AVAILABILITY_UNKNOWN_CHECKING:
// ARCore is checking the availability with a remote query.
// This function should be called again after waiting 200 ms
// to determine the query result.
handle_check_later();
return false;
case AR_AVAILABILITY_UNKNOWN_ERROR:
case AR_AVAILABILITY_UNKNOWN_TIMED_OUT:
// There was an error checking for AR availability.
// This may be due to the device being offline.
// Handle the error appropriately.
handle_unknown_error();
return false;
default: // All enum cases have been handled.
return false;
}
}
세션 만들기
ARCore에서 세션을 만들고 구성합니다.
// Create a new ARCore session.
ArSession* ar_session = NULL;
CHECK(ArSession_create(env, context, &ar_session) == AR_SUCCESS);
// Create a session config.
ArConfig* ar_config = NULL;
ArConfig_create(ar_session, &ar_config);
// Do feature-specific operations here, such as enabling depth or turning on
// support for Augmented Faces.
// Configure the session.
CHECK(ArSession_configure(ar_session, ar_config) == AR_SUCCESS);
세션 닫기
ArSession
는 상당한 양의 네이티브 힙 메모리를 소유합니다. 실패
명시적으로 세션을 종료하면 앱의 네이티브 메모리가 부족해지고
비정상 종료됩니다. AR 세션이 더 이상 필요하지 않으면 다음을 호출합니다.
ArSession_destroy()
드림
리소스를 해제할 수 있습니다
// Release memory used by the AR session.
ArSession_destroy(session);
다음 단계
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-07-26(UTC)
[null,null,["최종 업데이트: 2025-07-26(UTC)"],[[["\u003cp\u003eARCore sessions manage all AR processes like motion tracking and environmental understanding, and are accessed via the \u003ccode\u003eArSession\u003c/code\u003e object.\u003c/p\u003e\n"],["\u003cp\u003eBefore starting a session, verify ARCore is installed and updated using \u003ccode\u003eArCoreApk_checkAvailability\u003c/code\u003e to ensure smooth functionality.\u003c/p\u003e\n"],["\u003cp\u003eSessions can be configured to enable features like Depth API, Augmented Faces, or Cloud Anchors, providing flexibility for various AR experiences.\u003c/p\u003e\n"],["\u003cp\u003eTo avoid memory leaks and potential crashes, release session resources by calling \u003ccode\u003eArSession_destroy()\u003c/code\u003e when the session is no longer needed.\u003c/p\u003e\n"]]],[],null,["# Configure an ARCore session in Android NDK\n\nConfigure an ARCore session to build AR experiences for your app.\n\nWhat is a session?\n------------------\n\nAll [AR processes](/ar/discover/concepts), such as motion tracking,\nenvironmental understanding, and lighting estimation, happen inside an ARCore\nsession. [`ArSession`](/ar/reference/c/group/ar-session) is the main entry point to the ARCore\nAPI. It manages the AR system state and handles the session lifecycle, allowing\nthe app to create, configure, start, or stop a session. Most importantly, it\nenables the app to receive frames that allow access to the camera image and\ndevice pose.\n\nThe session can be used to configure the following features:\n\n- [Lighting Estimation](/ar/develop/lighting-estimation)\n- [Cloud Anchors](/ar/develop/cloud-anchors)\n- [Augmented Images](/ar/develop/augmented-images)\n- [Augmented Faces](/ar/develop/augmented-faces)\n- [Depth API](/ar/develop/depth)\n- [Instant Placement](/ar/develop/instant-placement)\n- [ARCore Geospatial API](/ar/develop/geospatial)\n\nVerify that ARCore is installed and up to date\n----------------------------------------------\n\nBefore creating an [`ArSession`](/ar/reference/c/group/ar-session), verify that ARCore is installed and up to date.\nIf ARCore isn't installed, session creation fails and any subsequent\ninstallation or upgrade of ARCore requires an app restart.\n\n\u003cbr /\u003e\n\n```c\n/*\n * Check if ARCore is currently usable, i.e. whether ARCore is supported and\n * up to date.\n */\nint32_t is_arcore_supported_and_up_to_date(void* env, void* context) {\n ArAvailability availability;\n ArCoreApk_checkAvailability(env, context, &availability);\n switch (availability) {\n case AR_AVAILABILITY_SUPPORTED_INSTALLED:\n return true;\n case AR_AVAILABILITY_SUPPORTED_APK_TOO_OLD:\n case AR_AVAILABILITY_SUPPORTED_NOT_INSTALLED: {\n ArInstallStatus install_status;\n // ArCoreApk_requestInstall is processed asynchronously.\n CHECK(ArCoreApk_requestInstall(env, context, true, &install_status) ==\n AR_SUCCESS);\n return false;\n }\n case AR_AVAILABILITY_UNSUPPORTED_DEVICE_NOT_CAPABLE:\n // This device is not supported for AR.\n return false;\n case AR_AVAILABILITY_UNKNOWN_CHECKING:\n // ARCore is checking the availability with a remote query.\n // This function should be called again after waiting 200 ms\n // to determine the query result.\n handle_check_later();\n return false;\n case AR_AVAILABILITY_UNKNOWN_ERROR:\n case AR_AVAILABILITY_UNKNOWN_TIMED_OUT:\n // There was an error checking for AR availability.\n // This may be due to the device being offline.\n // Handle the error appropriately.\n handle_unknown_error();\n return false;\n\n default: // All enum cases have been handled.\n return false;\n }\n}\n```\n\nCreate a session\n----------------\n\nCreate and configure a session in ARCore. \n\n```c\n// Create a new ARCore session.\nArSession* ar_session = NULL;\nCHECK(ArSession_create(env, context, &ar_session) == AR_SUCCESS);\n\n// Create a session config.\nArConfig* ar_config = NULL;\nArConfig_create(ar_session, &ar_config);\n\n// Do feature-specific operations here, such as enabling depth or turning on\n// support for Augmented Faces.\n\n// Configure the session.\nCHECK(ArSession_configure(ar_session, ar_config) == AR_SUCCESS);\n```\n\nClose a session\n---------------\n\n`ArSession` owns a significant amount of native heap memory. Failure to\nexplicitly close the session may cause your app to run out of native memory and\ncrash. When the AR session is no longer needed, call\n[`ArSession_destroy()`](/ar/reference/c/group/ar-session#arsession_destroy)\nto release resources. \n\n```c\n// Release memory used by the AR session.\nArSession_destroy(session);\n```\n\nNext steps\n----------\n\n- [ARCore quickstart for Android NDK](/ar/develop/c/quickstart)"]]