> For the complete documentation index, see [llms.txt](https://sungcheol-kim.gitbook.io/android-ndk-debugging/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sungcheol-kim.gitbook.io/android-ndk-debugging/chapter6.md).

# NDK 빌드 설정하기

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

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

```groovy
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'
}
```

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

```groovy
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` 파일 내용이다.

```groovy
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'
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://sungcheol-kim.gitbook.io/android-ndk-debugging/chapter6.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
