NDK 빌드 설정하기

안드로이드 스튜디오 1.3부터는 NDK 빌드 설정을 모두 모듈의 build.gradle 파일에 적어야 한다. 그래야 네이티브 디버깅이 가능하다.

build.gradle을 설정하는 것은 간단하다. 우선 만들려고 하는 NDK 모듈의 이름을 정의해 준다.

apply plugin: 'com.android.model.application'

model {
    ...

    android.ndk {
        moduleName = "hello-jni"
    }
    ...
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.1'
}

그리고 디버깅을 해볼 것이기 때문에 네이티브와 앱 모듈을 디버깅이 가능하도록 설정한다.

apply plugin: 'com.android.model.application'

model {
    ...

    android.buildTypes {
        release {
            isMinifyEnabled = false
            proguardFiles += file('proguard-rules.txt')
        }

        debug {
            isJniDebuggable = true
            isDebuggable = true
        }
    }
    ...
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.1'
}

이렇게 하면 디버깅이 가능한 NDK 빌드 구성은 끝난다. 아래는 전체 build.gradle 파일 내용이다.

apply plugin: 'com.android.model.application'

model {
    android {
        compileSdkVersion = 22
        buildToolsVersion = "22.0.1"

        defaultConfig.with {
            applicationId = "kr.pe.burt.hellojni"
            minSdkVersion.apiLevel = 15
            targetSdkVersion.apiLevel = 22
            versionCode = 1
            versionName = "1.0"
        }

        compileOptions.with {
            sourceCompatibility = JavaVersion.VERSION_1_7
            targetCompatibility = JavaVersion.VERSION_1_7
        }
    }

    android.ndk {
        moduleName = "hello-jni"
    }

    android.buildTypes {
        release {
            isMinifyEnabled = false
            proguardFiles += file('proguard-rules.txt')
        }

        debug {
            isJniDebuggable = true
            isDebuggable = true
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.1'
}

Last updated