Skip to content

Instantly share code, notes, and snippets.

@evasyuk
Forked from eleventigers/build.gradle
Created May 18, 2016 20:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evasyuk/dba55bdab9b6938b5a6a7dfbbc7f0461 to your computer and use it in GitHub Desktop.
Save evasyuk/dba55bdab9b6938b5a6a7dfbbc7f0461 to your computer and use it in GitHub Desktop.
import org.apache.tools.ant.taskdefs.condition.Os
def getPlatformNdkBuildCommand() {
def rootDir = project.rootDir
def localProperties = new File(rootDir, "local.properties")
if (localProperties.exists()) {
Properties properties = new Properties()
localProperties.withInputStream {
instr -> properties.load(instr)
}
def ndkDir = properties.getProperty('ndk.dir')
if (ndkDir == null) {
throw new GradleException("The ndk.dir property in local.propeties is not set")
}
def ndkBuild = Os.isFamily(Os.FAMILY_WINDOWS) ? "$ndkDir/ndk-build.cmd" : "$ndkDir/ndk-build"
return ndkBuild
} else {
throw new GradleException("The local.properties file does not exist")
}
}
apply plugin: 'com.android.library'
dependencies {
//...
}
android {
compileSdkVersion 21
buildToolsVersion '21.1.2'
sourceSets.main {
jniLibs.srcDir 'src/main/libs'
jni.srcDirs = [] //disable automatic ndk-build call
}
defaultConfig {
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
lintOptions {
disable 'InvalidPackage'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
}
}
// Manually call ndk-build to re-compile jni libs
task task1(type: Exec) {
def ndkBuild = getPlatformNdkBuildCommand()
commandLine "$ndkBuild", '-j8', '-C', file('yourjnidir').absolutePath
}
task task2(type: Exec) {
def ndkBuild = getPlatformNdkBuildCommand()
commandLine "$ndkBuild", '-j8', '-C', file('yourotherjnidir').absolutePath
}
task2.dependsOn task1
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn task2
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment