Skip to content

Instantly share code, notes, and snippets.

@cawka
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cawka/07e82ec156112b1456a6 to your computer and use it in GitHub Desktop.
Save cawka/07e82ec156112b1456a6 to your computer and use it in GitHub Desktop.
import org.apache.tools.ant.taskdefs.condition.Os
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "net.named_data.nfd"
minSdkVersion 14
targetSdkVersion 21
versionCode 2001
versionName "0.2.1"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
java.srcDirs "src/main/java"
res.srcDirs "src/main/res"
jniLibs.srcDir 'src/main/libs'
jni.srcDirs = [] //disable automatic ndk-build call
}
androidTest.setRoot('tests')
androidTest.java.srcDirs = ['tests/src']
}
splits {
abi {
enable true // enable ABI split feature to create one APK per ABI
universalApk true //generate an additional APK that targets all the ABIs
}
}
// map for the version code
// versionCode digit for each supported ABI, with 64bit>32bit and x86>armeabi-*
project.ext.versionCodes = ['armeabi': 1,
'armeabi-v7a': 2,
'arm64-v8a': 3,
'mips': 5,
'mips64': 6,
'x86': 8,
'x86_64': 9]
android.applicationVariants.all { variant ->
// assign different version code for each output
variant.outputs.each { output ->
output.versionCodeOverride = project.ext.versionCodes.get(
output.getFilter(
com.android.build.OutputFile.ABI), 0) * 1000000 +
defaultConfig.versionCode
}
}
// call regular ndk-build(.cmd) script from app directory
task ndkBuild(type: Exec) {
commandLine getNdkBuildCmd(), '-C', file('src/main').absolutePath
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
task cleanNative(type: Exec) {
commandLine getNdkBuildCmd(), '-C', file('src/main').absolutePath, 'clean'
}
clean.dependsOn cleanNative
}
def getNdkBuildCmd() {
if (System.env.ANDROID_NDK_ROOT != null)
return System.env.ANDROID_NDK_ROOT
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
String ndk_dir = properties.getProperty('ndk.dir', null)
if (ndk_dir == null) {
throw new GradleException("NDK location not found. Define location with ndk.dir in the local.properties file or with an ANDROID_NDK_ROOT environment variable.")
}
String ndk_build = ndk_dir + "/ndk-build"
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
ndk_build += ".cmd"
}
return ndk_build
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.android.support:support-v4:21.0.3'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment