Android : android studio 1.0 + ndk how to use custom makefiles

on Friday, December 12, 2014


Just migrated from eclipse to android studio but ndk compilation is really a pain. How can I use my custom makefile to compile my jni libraries using android studio? I tried to make a gradle task for that purpose. Check out my gradle file:



apply plugin: 'com.android.application'

android {
compileSdkVersion 21
buildToolsVersion "21.1.2"

sourceSets.main {
jniLibs.srcDir 'src/main/libs'
jni.srcDirs = [] //disable automatic ndk-build call
}

defaultConfig {
applicationId "com.example.exampleApp"
minSdkVersion 9
targetSdkVersion 21
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}

ndk {
moduleName "nativeLib"
}
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}

dependencies {
compile project(':smoothProgressBarLib')
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.google.android.gms:play-services:+'
compile files('libs/dexguard_util.jar')
}

task buildNative(type: Exec) {
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
def ndkDir = properties.getProperty('ndk.dir')
def ndkBuild = ndkDir + File.separator + "ndk-build.cmd";
def ndkBuildingDir = new File("src/main");

commandLine ndkBuild, '-C', ndkBuildingDir.absolutePath
}
tasks.withType(JavaCompile) { compileTask -> compileTask.dependsOn buildNative }


But I get the following error on windows 8.1



Process 'command 'C:\Users\Thanos\android-ndk-r10d\ndk-build.cmd'' finished with non-zero exit value 2


Any ideas what Am I doing wrong? It's driving me crazy


0 comments:

Post a Comment