Generating a build.xml for an Android project

If you want to automate builds of your Android applications, you will need to generate a build.xml file for your project for use with Ant. While it’s not clear from the Android Dev docs how to do this, it is actually very simple:

$ ANDROID_SDK/tools/android update project -p DIR_OF_PROJECT -n "NAME_OF_APP" -s -t ANDROID_TARGET_ID

Where ANDROID_SDK is the location of your Android SDK installation, DIR_OF_PROJECT is the path to your project folder and NAME_OF_APP is the name of your app. ANDROID_TARGET_ID is the identifier of one of the Android versions you have installed as part of your SDK, but note that the target ID is not the same as the Android version you are targeting. You can view the target IDs for all the installed Android versions using the list command: 

$ ANDROID_SDK/tools/android list targets

A successful run generates a build.xml file (and supporting properties files) in your project folder that you can now use to build your APK using:

$ ant release

This creates an unsigned APK that you will still need to sign before releasing but luckily you can also automate that. If you would like to only create a debug build, use ant debug instead.

The full list of options available for android update project are:

  -l --library    : Directory of an Android library to add, relative to this project's directory.
  -p --path       : The project's directory. [required]
  -n --name       : Project name.
  -t --target     : Target ID to set for the project.
  -s --subprojects: Also updates any projects in sub-folders, such as test projects.

Backup MySQL to S3 in 30 seconds

One of the most tedious parts of setting up a database for your new app is backing it up. So much so that you will almost always leave it for last if you remember to do it at all. However, with the risk of data corruption, server corruption or simple server failure looming it’s an important part of service continuity.

The good news is that there is a 30 second way to set up regular backups of your MySQL database into Amazon S3. This assumes you already have a MySQL database set up and an S3 account with a bundle created for your backups.

Step 1. Install s3cmd

s3cmd is a set of easy tools for working with S3 from the shell. If you are using Ubuntu it’s as easy as:

$sudo apt-get install s3cmd

Step 2. Create a script 

Create an executable script with the following contents:

export BACKUP_FILE=my_db.backup.sql.gz
export DATABASE_SCHEMA_NAME=my_schema
export S3_BUNDLE=myBundle
mysqldump -uroot $DATABASE_SCHEMA_NAME > temp.sql
gzip temp.sql
mv temp.sql.gz $BACKUP_FILE

This uses mysqldump to dump the database contents to a temporary SQL file, gzip compresses it and uploads it to S3 using the s3cmd put. Note that you should change DATABASE_SCHEMA_NAME, S3_BUNDLE and BACKUP_FILE to the values specific to your application.

Step 3. Set up Cron

Finally, just use <code>crontab -e</code> to create a cron entry to run this script every night. An example that runs it everynight at midnight:

# m h  dom mon dow   command
0  0  *  *  *  /home/ubuntu/backup/

You’re Done!

Congratulations, your database will be backed up to S3 every night for you.

To Err Is Human

brain Forbes has a profile of a stealth software company called Pramana which is looking to replace the ubiquitous CAPTCHA with something better. Pramana analyzes your behavior when you browse a website to decide if you are human or not and then uses that to allow/prevent access to human-only actions. While there aren’t too many details they might be using mouse movements, click times and other indicators of human reaction time.

CAPTCHAs are notoriously inadequate for preventing spam as OCR technology continues to improve. Tesseract is one popular tool that is supposedly used by spammers. Forbes also points out that most of the companies that suffer from CAPTCHA breakage fund the projects and research that lead to the OCR tools to break their CAPTCHAs.

I’ve always thought a fun solution to this problem is to include a fake ad in your advertisement space that asks “If you’re a human, click here”. Most spam bots won’t be sophisticated enough to find a randomly placed animated image and click on it. Then again, humans don’t click on ads very much either. Even I would be afraid of admitting I was human, fearing being sold some kind of “humanity enhancement” pill.

It makes you taller, you know.