How to quickly compile all the Android samples via command line?

The procedure described here is working only for the “legacy” branch of Android SDK, as the later version are all using “Gradle” now (procedure to compile to be covered in another blog).

First the prerequisites (for Ubuntu 14.04 64-bit host environment, and Android SDK has been installed in /opt/android-sdk-linux directory):

1. Update Android SDK:

cd /opt/android-sdk-linux
tools/android update sdk –no-ui

2. Ensure “ant” is installed: “sudo apt-get install ant”.

3. Ensure java and javac is installed, version 7 preferred. (Java 6 confirmed will give errors).

4. Next, “cd /opt/android-sdk-linux/samples/android-22/legacy” to the Android version 22 legacy branch.

Using this script (named as “myant”):

#!/bin/bash

export ANDROID_SDK=/opt/android-sdk-linux
export ANDROID_HOME=/opt/android-sdk-linux

$ANDROID_SDK/tools/android update project –path . –target android-21

ant debug

(Noticed above that I specified the target as Android version 21).

5. And then run the following script (ensuring that the above “myant” is in your $PATH):

list=”AccelerometerPlay/ \
ActionBarCompat/ \
AndroidBeamDemo/ \
ApiDemos/ \
AppNavigation/ \
BackupRestore/ \
BasicGLSurfaceView/ \
BluetoothHDP/ \
ContactManager/ \
CrossCompatibility/ \
CubeLiveWallpaper/ \
GestureBuilder/ \
HelloEffects/ \
Home/ \
HoneycombGallery/ \
JetBoy/ \
KeyChainDemo/ \
LunarLander/ \
MultiResolution/ \
NotePad/ \
RandomMusicPlayer/ \
RenderScript/ \
SampleSyncAdapter/ \
SearchableDictionary/ \
SipDemo/ \
SkeletonApp/ \
Snake/ \
SoftKeyboard/ \
SpellChecker/ \
Spinner/ \
SpinnerTest/ \
TicTacToeLib/ \
TicTacToeMain/ \
ToyVpn/ \
TtsEngine/ \
UiAutomator/ \
VoicemailProviderDemo/ \
VoiceRecognitionService/ \
WeatherListWidget/ \
WidgetPreview/ \
WiFiDirectDemo/ \
WiFiDirectServiceDiscovery/ \
Wiktionary/ \
WiktionarySimple/ \
XmlAdapters/”

for name in $list
do
if
[ -f “$name/AndroidManifest.xml” ]
then
cd $name
myant
cd ..
else
echo $name NOTBUILD
fi
done

All the samples will build successfully (just grep for successful) but only three subdirectory remain untouch: Renderscript, UiAutomator, and SpellChecker. Just “cd” to specific directory involved, and execute “myant” whenever AndroidManifest.xml is found.

Only UiAutomator remained cannot be compiled, as it does not comes with “AndroidManifest.xml” file.

Advertisements

One response to this post.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: