NDK 시작하기
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
네이티브 개발 키트(NDK)는 Android에서 C 및 C++ 코드를 사용할 수 있게 해주는 일련의 도구 모음으로, 네이티브 액티비티를 관리하고 센서 및 터치 입력과 같은 실제 기기 구성요소에 액세스하는 데 사용할 수 있는 플랫폼 라이브러리를 제공합니다. NDK는 앱을 개발할 때 자바 코드와 프레임워크 API만 사용해야 하는 대부분의 초심자 Android 프로그래머에게는 적합하지 않을 수 있지만 다음과 같은 작업을 하나 이상 해야 하는 상황에서 유용할 수 있습니다.
- 기기의 성능을 최대한 활용하여 짧은 지연 시간을 구현해야 하거나 게임 또는 물리학 시뮬레이션과 같은 컴퓨팅 집약적 애플리케이션을 실행해야 하는 상황
- 본인 또는 다른 개발자의 C 또는 C++ 라이브러리를 재사용하는 경우
Android 스튜디오 2.2 이상을 사용하면 NDK를 활용하여 C 및 C++ 코드를 네이티브 라이브러리로 컴파일하고 IDE의 통합 빌드 시스템인 Gradle을 통해 APK로 패키징할 수 있습니다. 그러면 자바 코드에서 자바 네이티브 인터페이스(JNI) 프레임워크를 통해 네이티브 라이브러리의 함수를 호출할 수 있습니다. Gradle 및 Android 빌드 시스템에 관한 자세한 내용은 빌드 구성을 참조하세요.
Android 스튜디오에서 네이티브 라이브러리를 컴파일하는 기본 빌드 도구는 CMake입니다. 빌드 도구 키트를 사용하는 기존 프로젝트의 수가 워낙 많아서 Android 스튜디오에서는 ndk-build도 지원합니다. 하지만 새로운 네이티브 라이브러리를 생성하려면 CMake를 사용해야 합니다.
이 가이드에서는 Android 스튜디오에서 NDK를 시작하고 실행하는 데 필요한 정보를 제공합니다. Android 스튜디오의 최신 버전이 없다면 지금 다운로드 및 설치하세요.
실험용 Gradle 사용자 주의사항: 네이티브 프로젝트에서 이미 CMake 또는 ndk-build를 사용하고 있거나 안정적인 Gradle 빌드 시스템 버전을 사용하길 원하거나 CCache와 같은 부가기능 도구를 지원하려면 플러그인 버전 2.2.0 이상으로 이전하고 CMake 또는 ndk-build를 사용하여 네이티브 라이브러리를 빌드하는 것이 좋습니다.
위의 경우에 해당하지 않는다면 계속 Gradle의 시험용 버전 및 Android 플러그인을 사용할 수 있습니다.
NDK 및 도구 다운로드
앱의 네이티브 코드를 컴파일하고 디버그하려면 다음 구성요소가 필요합니다.
- Android 네이티브 개발 키트(NDK): Android에서 C 및 C++ 코드를 사용할 수 있도록 해주는 도구 모음입니다.
- CMake: Gradle과 함께 작동하여 네이티브 라이브러리를 빌드하는 외부 빌드 도구입니다. ndk-build만 사용하려는 경우에는 이 구성요소가 필요하지 않습니다.
-
LLDB: Android 스튜디오에서 네이티브 코드를 디버깅하는 데 사용하는 디버거입니다.
이러한 구성요소 설치에 관한 자세한 내용은 NDK 및 CMake 설치 및 구성을 참조하세요.
네이티브 프로젝트 만들기 또는 가져오기
Android 스튜디오를 설정하면 간단하게 C/C++ 지원 기능을 활용하여 새 프로젝트를 생성할 수 있습니다. 그러나 네이티브 코드를 기존 Android 스튜디오 프로젝트로 추가하거나 가져오려면 다음 기본 프로세스를 따라야 합니다.
- 새로운 네이티브 소스 파일을 생성하여 Android 스튜디오 프로젝트에 추가합니다.
- 네이티브 코드가 이미 있거나 미리 빌드된 네이티브 라이브러리를 가져오려면 이 단계를 건너뛰어도 됩니다.
-
CMake 빌드 스크립트를 생성하여 네이티브 소스를 라이브러리로 빌드하는 방법을 CMake에 알립니다. 미리 빌드된 라이브러리나 플랫폼 라이브러리를 가져와서 연결하려는 경우에도 이 빌드 스크립트가 필요합니다.
- 기존 네이티브 라이브러리에 이미
CMakeLists.txt
빌드 스크립트가 있거나 ndk-build를 사용하면서 Android.mk
빌드 스크립트를 포함했다면 이 단계를 건너뛰어도 됩니다.
-
CMake 또는 ndk-build 스크립트 파일 경로를 제공하여 Gradle을 네이티브 라이브러리에 연결합니다. Gradle은 빌드 스크립트를 사용하여 소스 코드를 Android 스튜디오 프로젝트로 가져오고 네이티브 라이브러리(SO 파일)를 APK로 패키징합니다.
참고: 기존 프로젝트에서 지원이 중단된 ndkCompile
도구를 사용한다면 Gradle을 구성하여 CMake 또는 ndk-build를 사용하기 전에 build.properties
파일을 열고 다음 코드 행을 삭제해야 합니다.
// Remove this line
android.useDeprecatedNdk = true
-
Run
을 클릭하여 앱을 빌드하고 실행합니다. 그러면 Gradle에서 CMake 또는 ndk-build 프로세스를 종속 항목으로 추가하여 네이티브 라이브러리를 컴파일 및 빌드한 후 APK로 패키징합니다.
앱이 실제 기기나 에뮬레이터에서 실행되면 Android 스튜디오를 사용해 앱을 디버그할 수 있습니다. NDK 및 구성요소에 관한 자세한 내용은 개념 페이지를 참고하세요.
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-07-26(UTC)
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["필요한 정보가 없음","missingTheInformationINeed","thumb-down"],["너무 복잡함/단계 수가 너무 많음","tooComplicatedTooManySteps","thumb-down"],["오래됨","outOfDate","thumb-down"],["번역 문제","translationIssue","thumb-down"],["샘플/코드 문제","samplesCodeIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-07-26(UTC)"],[],[],null,["# Get started with the NDK\n\nThe Native Development Kit (NDK) is a set of tools that allows you to use C\nand C++ code with Android, and provides [platform libraries](/ndk/guides/stable_apis) you can use to manage\nnative activities and access physical device components, such as sensors and\ntouch input. The NDK may not be appropriate for most novice Android\nprogrammers who need to use only Java code and framework APIs to develop\ntheir apps. However, the NDK can be useful for cases in which you need to do\none or more of the following:\n\n- Squeeze extra performance out of a device to achieve low latency or run computationally intensive applications, such as games or physics simulations.\n- Reuse your own or other developers' C or C++ libraries.\n\n\nUsing [Android Studio 2.2 and higher](/studio), you can\nuse the NDK to compile C and C++ code into a native library and package it\ninto your APK using Gradle, the IDE's integrated build system. Your Java code\ncan then call functions in your native library through the [Java Native Interface (JNI)](http://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/jniTOC.html) framework. To learn\nmore about Gradle and the Android build system, read [Configure Your Build](/studio/build).\n\n\nAndroid Studio's default build tool to compile native libraries is [CMake](https://cmake.org/). Android Studio also\nsupports [ndk-build](/ndk/guides/ndk-build) due to the large\nnumber of existing projects that use the build toolkit. However, if you are\ncreating a new native library, you should use CMake.\n\n\nThis guide gives you the information you need to get up and running with the\nNDK on Android Studio. If you don't have the latest version of Android\nStudio, [download and install it now](/studio).\n\n\n**Attention experimental Gradle users:** Consider [migrating to plugin version 2.2.0 or higher](http://tools.android.com/tech-docs/new-build-system/gradle-experimental/migrate-to-stable), and using CMake or ndk-build\nto build your native libraries if any of the following apply to you: Your\nnative project already uses CMake or ndk-build; you would rather use a stable\nversion of the Gradle build system; or you want support for add-on tools,\nsuch as [CCache](https://ccache.samba.org/).\nOtherwise, you can continue to [use\nthe experimental version of Gradle and the Android plugin](http://tools.android.com/tech-docs/new-build-system/gradle-experimental).\n\nDownload the NDK and tools\n--------------------------\n\n\nTo compile and debug native code for your app, you need the following\ncomponents:\n\n- The Android Native Development Kit (NDK): a set of tools that allows you to use C and C++ code with Android.\n- CMake: an external build tool that works alongside Gradle to build your native library. You do not need this component if you only plan to use ndk-build.\n- *LLDB*: the debugger Android Studio uses to debug native code.\n\n\nFor information on installing these components, see [Install and configure the NDK and CMake](/studio/projects/install-ndk).\n\nCreate or import a native project\n---------------------------------\n\n\nOnce you set up Android Studio, you can simply [Create a New Project with\nC/C++ Support](/studio/projects/add-native-code#new-project). However, if you want to add or import native code to an\nexisting Android Studio project, you need to follow this basic process:\n\n1. [Create new\n native source files](/studio/projects/add-native-code#create-sources) and add them to your Android Studio project.\n - You can skip this step if you already have native code or want to import a prebuilt native library.\n2. [Create\n a CMake build script](/studio/projects/configure-cmake#create_script) to tell CMake how to build your native sources into a library. You also require this build script if you are importing and linking against prebuilt or platform libraries.\n - You can skip this step if your existing native library already has a `CMakeLists.txt` build script, or uses ndk-build and includes an [`Android.mk`](/ndk/guides/android_mk) build script.\n3. [Link Gradle to\n your native library](/studio/projects/gradle-external-native-builds) by providing a path to your CMake or ndk-build script file. Gradle uses the build script to import source code into your Android Studio project and package your native library (the SO file) into the APK.\n\n\n **Note:** If your existing project uses the deprecated\n `ndkCompile` tool, you should open your\n `build.properties` file and remove the following line of code\n before configuring Gradle to use CMake or ndk-build: \n\n ```\n // Remove this line\n android.useDeprecatedNdk = true\n ```\n4. [Build and run your app](/studio/run) by clicking **Run** . Gradle adds your CMake or ndk-build process as a dependency to compile, build, and package your native library with your APK.\n\n\nOnce your app is running on a physical device or the emulator, you can use\nAndroid Studio to [Debug your app](/studio/debug).\nOtherwise, to learn more about the NDK and its components, read the [Concepts](/ndk/guides/concepts) page."]]