Last active
August 29, 2015 14:12
-
-
Save kakajika/da449e21dcb899ed3994 to your computer and use it in GitHub Desktop.
Android NDK build script for Gradle. GradleでNDKビルドをするスクリプト。
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
// ndkbuild.gradle | |
def useJar = true // libをJar化するかどうか | |
def jniDir = 'src/main/jni' | |
android { | |
sourceSets { | |
main { | |
jni.srcDirs = [] | |
jniLibs.srcDirs = useJar ? [] : [new File(buildDir, 'libs')] | |
} | |
} | |
} | |
task ndkBuild(type: Exec) { | |
def ndkDir = project.plugins.findPlugin('android').getNdkFolder() | |
commandLine "${ndkDir}/ndk-build", | |
"NDK_PROJECT_PATH=build", | |
"APP_BUILD_SCRIPT=${jniDir}/Android.mk", | |
"NDK_APPLICATION_MK=${jniDir}/Application.mk" | |
} | |
task ndkLibsToJar(type: Zip, dependsOn: 'ndkBuild') { | |
destinationDir new File(buildDir, 'libs') | |
baseName 'nativelibs' | |
extension 'jar' | |
from(new File(buildDir, 'libs')) { include '**/*.so' } | |
into 'lib/' | |
} | |
tasks.withType(AbstractCompile) { | |
compileTask -> compileTask.dependsOn useJar ? ndkLibsToJar : ndkBuild | |
} | |
dependencies { | |
compile fileTree(dir: new File(buildDir, 'libs'), include: '*.jar') | |
} |
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
// in build.gradle | |
apply plugin: 'android' | |
apply from: './ndkbuild.gradle' | |
... | |
// in local.properties | |
ndk.dir=path/to/ndk/root/directory | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment