You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

178 lines
5.1 KiB

// Android pEp JNI adapter Aar gradle build script
import org.apache.tools.ant.taskdefs.condition.Os
def pEpEngineSrc = hasProperty('pEpEngineSrc') ? pEpEngineSrc : "../../pEpEngine"
def buildAutomatic = hasProperty('buildAutomatic') ? buildAutomatic : "true"
def pEpAppPackageName = hasProperty('pEpAppPackageName') ? pEpAppPackageName : "com.pep.k9"
def externalInstallDir = file('external/data/data/' + pEpAppPackageName + '/app_opt')
def externalIncludePath = new File(externalInstallDir, 'include').absolutePath
def libetpanAndroid = file('external/libetpan/build-android')
def pEpEngineAndroid = new File(new File(pEpEngineSrc), 'build-android')
def pEpEngineDB = new File(new File(pEpEngineSrc), 'db')
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
}
}
apply plugin: 'android-library'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
// where to find generated Java source
java.srcDirs = ['../src', 'src']
// disable automatic ndk-build call, which ignore our Android.mk
jni.srcDirs = []
jniLibs.srcDir 'libs'
assets.srcDirs = ['assets', 'external/assets']
}
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
lintOptions {
abortOnError false
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
// call source generation makefile target
task genSources(type:Exec) {
workingDir '../src'
commandLine 'make', 'gensource'
}
// call external build (GnuPG, GPGME, etc)
task buildExternal(type:Exec) {
workingDir 'external'
commandLine 'make', 'all', 'PEP_PACKAGE_NAME='+pEpAppPackageName
}
task cleanExternal(type:Exec) {
workingDir 'external'
commandLine 'make', 'clean', 'PEP_PACKAGE_NAME='+pEpAppPackageName
}
// call pEpEngine Build
task buildpEpEngine(type:Exec) {
workingDir pEpEngineAndroid
environment['GPGME_INCLUDE_PATH'] = externalIncludePath
environment['LIBETPAN_PATH'] = libetpanAndroid.absolutePath
commandLine './build.sh'
}
if(buildAutomatic=="true"){
buildpEpEngine.dependsOn buildExternal
}
// unzip some of the dependencies
task unzipDeps(type: Copy) {
from zipTree(new File(pEpEngineAndroid, 'pEpEngine-android-1.zip'))
from zipTree(new File(libetpanAndroid, 'libetpan-android-1.zip'))
from zipTree(new File(libetpanAndroid, 'dependencies/openssl/openssl-android-1.zip'))
from zipTree(new File(libetpanAndroid, 'dependencies/cyrus-sasl/cyrus-sasl-android-1.zip'))
into file("${buildDir}")
}
if(buildAutomatic=="true"){
unzipDeps.dependsOn buildpEpEngine
}
// builds pEpEnginge's system.db
task buildpEpEngineSystemDB(type:Exec) {
workingDir pEpEngineDB
commandLine 'make', 'system.db'
}
// copy pEpEnginge's system.db to asset
task cpDBAssets(type: Copy) {
from file(new File(pEpEngineDB, 'system.db'))
into 'assets'
}
if(buildAutomatic=="true"){
cpDBAssets.dependsOn buildpEpEngineSystemDB
}
// call regular ndk-build(.cmd) script from app directory
task jniBuild(type: Exec) {
// In case ndk-gdb works one day, add: 'NDK_DEBUG=1',
commandLine getNdkBuildCmd(), 'V=1', 'GPGBUILD='+externalInstallDir.absolutePath
}
jniBuild.dependsOn genSources
jniBuild.dependsOn unzipDeps
jniBuild.dependsOn cpDBAssets
// Ensure this is done before java build
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn jniBuild
}
assemble.dependsOn unzipDeps
task jniClean(type: Exec) {
commandLine getNdkBuildCmd(), 'clean', 'GPGBUILD='+externalInstallDir.absolutePath
}
if(buildAutomatic=="true"){
clean.dependsOn cleanExternal
// ndk-build clean complains when .so are missing
// ensure jniClean happens before external clean
cleanExternal.dependsOn jniClean
}else{
clean.dependsOn jniClean
}
}
def getNdkDir() {
if (System.env.ANDROID_NDK != null)
return System.env.ANDROID_NDK
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
def ndkdir = properties.getProperty('ndk.dir', null)
if (ndkdir == null)
throw new GradleException("NDK location not found. Define location with ndk.dir in the local.properties file or with an ANDROID_NDK environment variable.")
return ndkdir
}
def getNdkBuildCmd() {
def ndkbuild = getNdkDir() + "/ndk-build"
if (Os.isFamily(Os.FAMILY_WINDOWS))
ndkbuild += ".cmd"
return ndkbuild
}