Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect Android deployment target from Gradle build file

I'm looking to extend my gradle build with a call to an external tool. The issue is that I need to provide the current CPU architecture that is currently being targeted, for example armeabi or arm64-v8a if the user has chosen to deploy to a physical device. I am having trouble finding a way of determining this information in the gradle build file.

Currently I am performing this action in a custom task which runs before preBuild, similar to this solution. Is there any way to detect the CPU architecture at this point?

task customTask(type: Exec) {
    commandLine "myTool.exe", "-architecture=$something"
}

preBuild.dependsOn customTask

I'm using the experimental plugin 0.7.0-beta3.

Thanks

like image 392
blyn Avatar asked Jan 20 '26 08:01

blyn


1 Answers

You can get the CPU architecture (ABI) of the connected device with an ADB shell command:

adb shell getprop ro.product.cpu.abi

For a Nexus 5 this would return armeabi-v7a as an example.

Now we have to wrap that command into a gradle method:

def getDeviceAbi() {
    return "adb shell getprop ro.product.cpu.abi".execute().text.trim()
}

Then you can simply call this method from your task:

task customTask(type: Exec) {
    commandLine "myTool.exe", "-architecture=" + getDeviceAbi()
}
preBuild.dependsOn customTask
like image 107
Floern Avatar answered Jan 22 '26 22:01

Floern



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!