Last active
August 29, 2015 13:56
-
-
Save eerock/9226601 to your computer and use it in GitHub Desktop.
JNI Build Wrapper for Android Studio
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
#!/bin/bash | |
# | |
# The purpose of this script is to aide building native libs in | |
# Android Studio using recent versions of Gradle 0.8.+. As of this | |
# version of the Gradle plugin building jni doesn't work just yet. | |
# So as a workaround you need to disable Gradle from building | |
# jni sources by adding the following to your project's build.gradle: | |
# | |
# android { | |
# sourceSets.main { | |
# jni.srcDirs = [] | |
# } | |
# } | |
# | |
# For now you need to build native code manually with ndk-build. | |
# I highly recommend creating a jni/Application.mk file because | |
# you can specify everything you need built: | |
# | |
# APP_ABI := all | |
# APP_PLATFORM := android-19 | |
# APP_PROJECT_PATH := /path/to/project/src/main | |
# | |
# This script invokes ndk-build, setting the obj output folder | |
# to the build/jni-obj folder, to align more with Android Studio, | |
# and the lib output folder to jniLibs. | |
# | |
# Finally, Gradle will pick up these libs in the jniLibs folder | |
# automatically now. No need to tell Gradle where to look for | |
# 'prebuilts'. | |
# | |
# The project path is hardcoded. I put this script in my path | |
# in order to invoke a jni build from anywhere. You can | |
# modify it as needed, or put yours in your project somewhere | |
# and get Gradle to run it for you. | |
# | |
# You can also do 'jnibuild.sh clean' if needed. | |
# | |
# set this to the directory where your jni folder resides... | |
PROJECTDIR="/path/to/project/src/main" | |
pushd ${PROJECTDIR} | |
( # subshell context for exported variables | |
export NDK_OUT="$PROJECTDIR/../../build/jni-obj"; | |
export NDK_LIBS_OUT="$PROJECTDIR/jniLibs"; | |
ndk-build -C ${PROJECTDIR} $1 | |
) | |
popd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment