Skip to content

Instantly share code, notes, and snippets.

@mackthehobbit
Created November 24, 2015 11:38
Show Gist options
  • Save mackthehobbit/2a73f3ad3eb653554d8d to your computer and use it in GitHub Desktop.
Save mackthehobbit/2a73f3ad3eb653554d8d to your computer and use it in GitHub Desktop.
Android Studio's default support for building NDK doesn't appear to ever work for me. Here's a way to make a build process work.
// add all of these to build.gradle (the one in your app directory, NOT the root of the project)
// to see all files and be able to add your jni directory, you might need to change the view from 'Android' to 'Project' in the file browser
// this goes inside android > defaultConfig (probably after all the other fields eg. versionCode etc)
sourceSets.main {
jniLibs.srcDir 'src/main/libs'
jni.srcDirs = [];
}
// these two go at the end of the 'android' block (but still inside it)
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
// change the path to where you have your android NDK installed
// also change ndk-build.cmd on platforms other than Windows
task ndkBuild(type: Exec) {
commandLine 'C:\\path\\to\\ndk\\ndk-build.cmd', '-C', file('src/main/jni').absolutePath
}
// that should be it; just change your AndroidManifest to suit your addon (permissions etc, and usually hasCode=false)
// and add your jni directory with native code, Android.mk + Application.mk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment