// 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 : "pep.android.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:2.2.0' } } allprojects { repositories { jcenter() } } apply plugin: 'com.android.library' android { compileSdkVersion 21 buildToolsVersion '25.0.0' 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 'commons-io:commons-io:2.4' } lintOptions { abortOnError false } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } ext { pEpEngineZip = new File(pEpEngineAndroid, 'pEpEngine-android-1.zip') libEtPanZip = new File(libetpanAndroid, 'libetpan-android-1.zip') // libOpenSslZip = new File(libetpanAndroid, 'dependencies/openssl/openssl-android-1.zip') // libSaslZip = new File(libetpanAndroid, 'dependencies/cyrus-sasl/cyrus-sasl-android-1.zip') } // call source generation makefile target task genSources(type:Exec) { workingDir '../src' commandLine 'make', 'gensource' } task cleanGenSource(type:Exec) { workingDir '../src' commandLine 'make', 'clean' } // call external build (GnuPG, GPGME, etc) task buildExternal(type:Exec) { workingDir 'external' commandLine 'make', 'build', 'PEP_PACKAGE_NAME='+pEpAppPackageName } task externalAssets(type:Exec) { workingDir 'external' commandLine 'make', 'assets', 'PEP_PACKAGE_NAME='+pEpAppPackageName } task cleanExternal(type:Exec) { workingDir 'external' commandLine 'make', 'clean', 'PEP_PACKAGE_NAME='+pEpAppPackageName } task cleanExternalAssets(type:Exec) { workingDir 'external' commandLine 'make', 'clean-assets', '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' } task cleanpEpEngine(type:Exec) { commandLine 'rm', '-f', pEpEngineZip.absolutePath } // unzip some of the dependencies task unzipDeps(type: Copy) { from zipTree(pEpEngineZip) from zipTree(libEtPanZip) // from zipTree(libOpenSslZip) // from zipTree(libSaslZip) into file("${buildDir}") } // 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' } // This ensures that assets are populated before collecting resources. preBuild.dependsOn(cpDBAssets) preBuild.dependsOn(externalAssets) // 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 // Ensure this is done before java build tasks.withType(JavaCompile) { compileTask -> compileTask.dependsOn jniBuild } task jniClean(type: Exec) { commandLine getNdkBuildCmd(), 'clean', 'GPGBUILD='+externalInstallDir.absolutePath ignoreExitValue = true } clean.dependsOn jniClean jniClean.dependsOn cleanGenSource cleanExternal.dependsOn jniClean clean.dependsOn cleanExternalAssets if(buildAutomatic=="true"){ buildpEpEngine.dependsOn buildExternal externalAssets.dependsOn buildExternal unzipDeps.dependsOn buildpEpEngine cpDBAssets.dependsOn buildpEpEngineSystemDB clean.dependsOn cleanExternal clean.dependsOn cleanpEpEngine } } 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 }