Looking for android version with ADB
I was trying to get my android version number with ADB (as I didn’t want to make excessive use of my fingers on a screen, you know
). I wanted to do it so I could make some scripts, but I didn’t really found a cool way to do so. Thankfully, android shell has a command wich will tell us all device info: getprop.
As this is an android shell stuff and not ADB itself, we’ll have to launch adb shell against it, and then parse the output, I’m using awk here to parse it
I’ll change awk internal field separator (IFS) with the -F flag to parse the output into key-value stuff and print only the value, I already knew the key, wich, for android version, is “build.version.release”
We can parse, csv with awk the same way as we’ll be doing this:
cat foo.csv| awk -F "," '/pattern/ {print $1 }'
At the end we’ll get version with just this simple piece of code:
version=$(adb shell getprop |awk -F":" '/build.version.release/ { print $2 }')
Update: I wanted it cleaner, so I removed [ and ] with tr.
version=$(adb shell getprop |awk -F":" '/build.version.release/ { print $2 }')|tr -d '[]'
Amazingly usefull for android debugging!
Making releases for python programs in android
It’s been a while since I lastest got Digenpy for android ready, so I decided to take a look at it again and re-do it. After I finised most of the work, I realized I didn’t have a build-and-test apk system, so I’ve built one.
Here are the steps I followed, as described by android documentation:
- Download android sdk
- Get java development kit (sun-java6-jdk in debian. Only available in debian stable at this time)
- Launch “android” executable from sdk tools/ directory and specify it to download the APIs you want, and the platform tools.
- Generate apk with ant *
- Align apk with zipalign from tools directory *
- Set up a virtual machine in emulator *
- Launch app in emulator *
* I’ve made a little script, hosted here , it also can do debian packages and windows exes (I will talk about it in my next article). After apk building it launches android emulator to test it.
Let’s get all of it togheter. We need to install a few things and configure the script.
First of all, we’ll need to install android SDK on a good path, like /usr/local/share/android-sdk.
$ wget http://dl.google.com/android/android-sdk_r15-linux.tgz -O - |tar xvzf - # mv android-sdk-linux /usr/local/share/android-sdk
Then, we install sun-java6-jdk, only debian stable is covered here.
# apt-get install sun-java6-jdk sun-java6-jre
Finally, we’ll install the android platform tools and sdk, launching (as root) the android app.
# /usr/local/share/android-sdk/tools/android
Inside there, we’ll select an API (I’ve chosen 10) and the platform-tools and SDK-tools.
To be able to emulate, first we’ll have to create the config for an emulator, we’ll do it trough tools/Manage AVDs
Now, we will download the template for android-python apps, uncompress it, and put our script on raw/res/script.py, then execute package_generator script.
wget http://android-scripting.googlecode.com/hg/android/script_for_android_template.zip unzip script_for_android_template.zip mv hello_world.py raw/res/script.py
Package_generator.sh apk
And there we have it: It will generate a nice APK, and launch the emulator with the apk installed so we can test it.




