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.
 
 
 
 
 
 

149 lines
4.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 pEpEngineAndroid = new File(new File(pEpEngineSrc), 'build-android')
def libetpanAndroid = new File(new File(pEpEngineSrc), '../libetpan/build-android')
def externalInstallDir = file('external/data/data/' + pEpAppPackageName + '/app_opt')
def externalIncludePath = new File(externalInstallDir, 'include').absolutePath
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
}
}
apply plugin: 'com.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']
}
}
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
}
// call pEpEngine Build
task buildpEpEngine(type:Exec) {
workingDir pEpEngineAndroid
environment['GPGME_INCLUDE_PATH'] = externalIncludePath
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
}
// copy pEpEnginge's system.db to asset
task cpDBAssets(type: Copy) {
from file(new File(new File(pEpEngineSrc), 'db/system.db'))
into 'assets'
}
// call regular ndk-build(.cmd) script from app directory
task jniBuild(type: Exec) {
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
}
task cleanNative(type: Exec) {
commandLine getNdkBuildCmd(), 'clean'
}
clean.dependsOn cleanNative
}
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
}