Skip to content

Instantly share code, notes, and snippets.

@oodavid
Last active December 21, 2015 10:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oodavid/6292979 to your computer and use it in GitHub Desktop.
Save oodavid/6292979 to your computer and use it in GitHub Desktop.
Android - Compile, Install, Run and Debug

Will require tweaking for your environment as I've hardcoded some binary paths.

Requires all the usual gubbins to compile android:

  • Apache ANT
  • Android
  • Android ADB
  • Android Monitor

If you want to use this with sublime-text, then you'll need a simple build script:

{
    "working_dir": "$project_path",
    "shell_cmd": "/path/to/android.compile.sh"
}
#!/bin/bash
#
# BE PRETTY
#
echo -e " "
echo -e " . ____ . ___________________________________________"
echo -e " |/ \| | |"
echo -e "[| \e[1;31m♥ ♥\e[00m |] | Android - Compile, Install, Run and Debug |"
echo -e " |___==___| / \e[1;30m© oodavid 2013\e[00m |"
echo -e " |___________________________________________|"
echo -e " "
#
# SETUP - extract some variables from the local files...
#
# build.xml
# PROJECT NAME MyAndroidApp
PROJECT=`grep -m 1 -o '<project name="[^"]*' build.xml | cut -c 16-`
# AndroidManifest.xml
# PACKAGE NAME - com.example.myandroid
PACKAGE=`grep -m 1 -o 'package\="[^"]*' AndroidManifest.xml | cut -c 10-`
# ACTIVITY - .AlarmMainActivity
ACTIVITY=`grep -m 1 -o '<activity android:name="[^"]*' AndroidManifest.xml | cut -c 25-`
# Be pretty
echo -e "\e[1;30mFrom build.xml\e[00m"
echo -e " \e[1;32mPROJECT \e[00m $PROJECT"
echo -e "\e[1;30mFrom AndroidManifest.xml\e[00m"
echo -e " \e[1;32mPACKAGE \e[00m $PACKAGE"
echo -e " \e[1;32mACTIVITY\e[00m $ACTIVITY"
echo -e " "
#
# BUILD AND RUN
#
# Must run in the correct context
cd /home/david/Documents/5-2
# Build the apk
ant debug
# Make sure it installs OK - http://stackoverflow.com/a/12359795
/home/david/Development/android-sdk-linux/platform-tools/adb -d uninstall $PACKAGE
# Install on the device
/home/david/Development/android-sdk-linux/platform-tools/adb -d install -r ./bin/$PROJECT-debug.apk
# Run the apk on the device
/home/david/Development/android-sdk-linux/platform-tools/adb shell am start -n $PACKAGE/$ACTIVITY
#
# DEBUGGING
#
# Open Debugger if not already open
if !( ps -e | grep "monitor$" > /dev/null )
then
/home/david/Development/android-sdk-linux/tools/monitor &
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment