Browse Source

PEMA-107 Only run buildExternal for connected devices

pull/25/head
ignaciogarcia 3 years ago
parent
commit
f20dd609a9
No known key found for this signature in database GPG Key ID: 5E6A455C909DD623
  1. 15
      android/build.gradle
  2. 56
      android/gradle/plugins/set-pep-jniadapter-archs.gradle

15
android/build.gradle

@ -8,7 +8,9 @@ def buildAutomatic = hasProperty('buildAutomatic') ? buildAutomatic : "true"
def threadsToUse = 1
def pEpEngineDB = new File(new File(pEpEngineSrc), 'db')
def archsToCompile = "arm arm64 x86 x86_64"
ext.archsToCompile = "arm arm64 x86 x86_64"
apply from: 'gradle/plugins/set-pep-jniadapter-archs.gradle'
buildscript {
repositories {
@ -117,9 +119,14 @@ android {
}
// call external build (GnuPG, GPGME, etc)
task buildExternal(type:Exec, dependsOn: 'genSources') {
workingDir 'external'
commandLine 'make', "-j${threadsToUse}", 'build', "archs=${archsToCompile}"
task buildExternal(dependsOn: ['genSources', 'setpEpJNIAdapterArchs']) {
doLast {
println("compiling for abis: ${project.archsToCompile}")
exec {
workingDir 'external'
commandLine 'make', "-j${threadsToUse}", 'build', "archs=${project.archsToCompile}"
}
}
}
task externalAssets(type:Exec) {

56
android/gradle/plugins/set-pep-jniadapter-archs.gradle

@ -0,0 +1,56 @@
task setpEpJNIAdapterArchs {
description = "Prepare pEpJNIAdapter to build with the first archs of each connected device."
doLast {
def serialNos = getConnectedDevicesIds()
println("Connected devices: $serialNos")
def abis = serialNos.collect { serialNo ->
convertAbiName(execCommand("adb -s ${serialNo} shell getprop ro.product.cpu.abilist", true).trim().split(",")[0])
}.toSet()
def sb = new StringBuilder()
for (String s : abis) {
sb.append(s)
sb.append(" ")
}
if (!abis.isEmpty()) {
project.archsToCompile = sb.toString().trim()
println("got archs to compile: ${project.archsToCompile}")
}
}
}
private List<String> getConnectedDevicesIds(boolean verbose = false) {
def lines = execCommand("adb devices", true, verbose).readLines()
lines.removeIf { it.trim().isEmpty() }
lines.remove(0)
if (lines.isEmpty()) return lines
return lines.collect { line ->
line.substring(0, line.indexOf("device")).trim()
}
}
static String convertAbiName(name) {
if (name == "armeabi-v7a") return "arm"
else if (name == "arm64-v8a") return "arm64"
else return name
}
private String execCommand(String command, boolean captureOutput = false, boolean verbose = false) {
def stdout = captureOutput ? new ByteArrayOutputStream() : null
exec {
if (verbose) {
println("running command: $command")
}
commandLine command.split(' ')
if (stdout != null) {
standardOutput = stdout
}
}
String out = null
if (stdout != null) {
out = stdout.toString()
stdout.close()
}
return out
}
Loading…
Cancel
Save