Created
March 23, 2015 15:11
-
-
Save bitristan/7f10723f868e17cb99ab to your computer and use it in GitHub Desktop.
use gradle to compile jni with custom Android.mk
This file contains hidden or 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
apply plugin: 'com.android.application' | |
android { | |
compileSdkVersion 21 | |
buildToolsVersion "21.1.2" | |
defaultConfig { | |
applicationId "com.your.application.id" | |
minSdkVersion 15 | |
targetSdkVersion 21 | |
versionCode 1 | |
versionName "1.0" | |
} | |
buildTypes { | |
release { | |
minifyEnabled false | |
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | |
} | |
} | |
sourceSets.main { | |
jni.srcDirs = [] | |
} | |
task buildNative(type: Exec, description: 'Compile JNI source via NDK') { | |
android.applicationVariants.all { variant -> | |
def ndkDir = android.plugin.ndkFolder | |
commandLine "$ndkDir/ndk-build", | |
'NDK_PROJECT_PATH=null', | |
'APP_BUILD_SCRIPT=src/main/jni/Android.mk', | |
"NDK_OUT=$buildDir/intermediates/ndk/${variant.dirName}/obj", | |
"NDK_LIBS_OUT=$buildDir/intermediates/ndk/${variant.dirName}/lib" | |
copy { | |
from "$buildDir/intermediates/ndk/${variant.dirName}/lib" | |
into "src/main/jniLibs" | |
} | |
} | |
} | |
task cleanNative(type: Exec, description: 'Clean JNI object files') { | |
android.applicationVariants.all { variant -> | |
def ndkDir = android.plugin.ndkFolder | |
commandLine "$ndkDir/ndk-build", | |
'NDK_PROJECT_PATH=null', | |
'APP_BUILD_SCRIPT=src/main/jni/Android.mk', | |
"NDK_OUT=$buildDir/intermediates/ndk/${variant.dirName}/obj", | |
"NDK_LIBS_OUT=$buildDir/intermediates/ndk/${variant.dirName}/lib", | |
'clean' | |
} | |
} | |
clean.dependsOn 'cleanNative' | |
tasks.withType(JavaCompile) { | |
compileTask -> compileTask.dependsOn buildNative | |
} | |
lintOptions { | |
abortOnError false | |
} | |
} | |
dependencies { | |
compile fileTree(dir: 'libs', include: ['*.jar']) | |
compile 'com.android.support:appcompat-v7:21.0.3' | |
compile 'com.android.support:support-v13:21.0.3' | |
compile 'com.android.support:support-v4:21.0.3' | |
compile project(':corelib') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment