Java,Android
Android NDK 빌드툴인 NDK-Build 와 CMake 정리
덜지
2018. 8. 2. 11:50
요약
안드로이드 스튜디오의 기본 빌드 툴은 CMake
안드로이드 스튜디오는 이미 사용 중인 기존 프로젝트가 너무 많아서 NDK-Build를 지원
만약 새 프로젝트를 만들 경우엔 CMake를 쓰는 것이 좋음
CMake
- Android, Linux, Windows, IOS 등 모든 타겟에서 빌드 가능
- 크로스 플랫폼을 사용한다면 CMake가 가장 좋음
- CMakeLists.txt 파일을 만들어줘야함 - CMake 빌드 스크립트 파일은 자동으로 생기지 않음
# Sets the minimum version of CMake required to build your native library.
# This ensures that a certain set of CMake features is available to
# your build.
cmake_minimum_required(VERSION 3.4.1)
# Specifies a library name, specifies whether the library is STATIC or
# SHARED, and provides relative paths to the source code. You can
# define multiple libraries by adding multiple add.library() commands,
# and CMake builds them for you. When you build your app, Gradle
# automatically packages shared libraries with your APK.
add_library( # Specifies the name of the library.
native-lib
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
src/main/cpp/file_name.cpp )
NDK-Build
- legacy 프로젝트들이 아직 많기때문에 Android Studio에서 NDK-Build를 지원
- Android.mk, Application.mk 파일 필요
- APP_PLATFORM은 안드로이드에서 minSdkVersion을 의미. 즉 NDK target API는 앱의 최소 API 지원 레벨을 의미
CMake와 NDK-Build Gradle 설정
// Encapsulates your external native build configurations.
externalNativeBuild {
// Encapsulates your CMake build configurations.
cmake {
// Provides a relative path to your CMake build script.
path "src/main/cpp/CMakeLists.txt"
}
// Encapsulates your ndkBuild build configurations.
ndkBuild {
// Provides a relative path to your ndkBuild Android.mk file.
path "src/main/cpp/Android.mk"
}
}