Created
January 14, 2015 15:21
-
-
Save eleventigers/e112fd76dd95e8e8ff5b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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