IT

android studio ndk

좋은열매디 2015. 5. 29. 17:17

빨간부분 추가, 프로젝트 내에 app-> build.gradle 파일 열고 

 apply plugin: 'com.android.application'



import org.apache.tools.ant.taskdefs.condition.Os
def getNdkBuildPath() {
    Properties properties = new Properties()
    properties.load(project.rootProject.file('local.properties').newDataInputStream())

    def command =  properties.getProperty('ndk.dir')
    if (Os.isFamily(Os.FAMILY_WINDOWS)) {
        command += "\\ndk-build.cmd"
    
else {
        command += "/ndk-build"
    
}

    return command
}

android {
    compileSdkVersion 23
    
buildToolsVersion "23.0.2"

    
defaultConfig {
        applicationId "andcast.hhh.test"
        
minSdkVersion 21
        
targetSdkVersion 23
        
versionCode 1
        
versionName "1.0"
    
}
    buildTypes {
        release {
            minifyEnabled false
            
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        
}
        debug {
        }
    }


    sourceSets.main {
        // Compile
 Native Library 위치하는 경로를 설정합니다.
        
jniLibs.srcDir 'src/main/libs'

        
// 
여기에 JNI Source 경로를 설정하면 Android Studio에서 기본적으로 지원하는 Native
        // Library Build
 이루어집니다 경우에 Android.mk Application.mk
        // 
자동으로 생성하기 때문에 편리하지만세부 설정이 어렵기 때문에 JNI Source
        // 
경로를 지정하지 않습니다.
        
jni.srcDirs = []
    }

    ext {
        // 
아직은 Task 내에서 Build Type 구분할 방법이 없기 때문에  Property
        // 
이용해 Native Library Debugging 가능하도록 Build  결정합니다.
        
nativeDebuggable = false
    
}

    // NDK
 ndk-build 명령을 이용하여 Native Library Build하기 위한 Task 정의합니다.
    //noinspection GroovyAssignabilityCheck
    
task buildNative(type: Exec, description'Compile JNI source via NDK') {
        if (nativeDebuggable) {
            commandLine getNdkBuildPath(), 'NDK_DEBUG=1''-C', file('src/main').absolutePath
        else {
            commandLine getNdkBuildPath(), '-C', file('src/main').absolutePath
        }
    }

    // App
 Java Code Compile  buildNative Task 실행하여 Native Library 같이
    // Build
되도록 설정합니다.
    
tasks.withType(JavaCompile) {
        compileTask -> compileTask.dependsOn buildNative
    }


}




gradle.properties 에

android.useDeprecatedNdk=true

추가!



Project Structure -> SDK Location -> Android NDK Location 경로 잘 되있는지 확인




빌드하면 끝!