#!/bin/bash #Big thanks to the author of: http://geosoft.no/development/android.html #1. no GRADLE files generated #2. openJDK/Sun JDK issues #3. Ant build hiding WHAT's GOING ON, so can't simply 'fix' in normal way, issues with symlinks. #SOLUTION: DIY! JAVA_HOME=/usr/local/java/jdk1.7.0_05 ANDROID_HOME=/local/saved/android/android-sdk-linux DEV_HOME=/local/saved/android/Project/MyProject PACKAGE=com.example.myproject ACTIVITY_CLASS=MyActivity APP_NAME=MyApp KEYSTORE=${DEV_HOME}/${APP_NAME}.keystore PACKAGE_PATH=${PACKAGE//.//} clear if [ -z "${TARGET}" ] ;then android list target read -p "Enter the target ID: " TARGET fi clear if [ -z ${AVD_NAME} ] ; then ${ANDROID_HOME}/tools/emulator -list-avds read -p "Select the AVD: " AVD_NAME fi function mkProject() { mkdir -p "${DEV_HOME}"/{src/${PACKAGE_PATH},res/{drawable,layout,values},obj,lib,bin,docs} #The src/ directory will hold java code and other source files in a package structure common for java projects. Using the reverse domain name system (Reverse DNS) for package names is optional but recommended. #The res/ directory will hold user provided resources like text strings, images, menues, layouts etc. The res/ sub directories have predefined names according to the Android resource documentation. #The obj/ directory will contain .class files and other secondary files produced by the Java tools as explained below. #The lib/ directory should hold 3rd-party .jar files the project depends on. #The bin/ directory will hold intermediate and final executables produced by the Android tools. #The docs/ directory will hold javadoc HTML documents for the project. If generated, the docs/index.html file will be the entry point. cat >"${DEV_HOME}"/AndroidManifest.xml < EOF #optionally create an AVD: #android --verbose create avd --name MySonyEricsson --target android-7 --sdcard 1024M #android --verbose delete avd --name MySonyEricsson #optionally create a key store! ${JAVA_HOME}/bin/keytool -genkeypair -validity 10000 -dname "CN=company name, OU=organisational unit, O=organisation, L=location, S=state, C=country code" -keystore ${DEV_HOME}/${APP_NAME}.keystore -storepass password -keypass password -alias AndroidTestKey -keyalg RSA -v cat > ${DEV_HOME}/src/${PACKAGE_PATH}/${ACTIVITY_CLASS}.java << EOF package ${PACKAGE}; import android.app.Activity; import android.content.res.Resources; import android.os.Bundle; import android.widget.TextView; public class ${ACTIVITY_CLASS} extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); TextView textView = new TextView(this); String text = getResources().getString(R.string.helloText); textView.setText(text); setContentView(textView); } } EOF cat > ${DEV_HOME}/res/values/strings.xml < Android Test Program Hello, world! EOF } function compile() { #compile process: ${ANDROID_HOME}/build-tools/23.0.1/aapt package -v -f -m -S ${DEV_HOME}/res -J ${DEV_HOME}/src -M ${DEV_HOME}/AndroidManifest.xml -I ${ANDROID_HOME}/platforms/${TARGET}/android.jar && \ ${JAVA_HOME}/bin/javac -verbose -d ${DEV_HOME}/obj -classpath ${ANDROID_HOME}/platforms/${TARGET}/android.jar:${DEV_HOME}/obj -sourcepath ${DEV_HOME}/src ${DEV_HOME}/src/${PACKAGE_PATH}/*.java && \ ${ANDROID_HOME}/build-tools/23.0.1/dx --dex --verbose --output=${DEV_HOME}/bin/classes.dex ${DEV_HOME}/obj ${DEV_HOME}/lib && \ ${ANDROID_HOME}/build-tools/23.0.1/aapt package -v -f -M ${DEV_HOME}/AndroidManifest.xml -S ${DEV_HOME}/res -I ${ANDROID_HOME}/platforms/${TARGET}/android.jar -F ${DEV_HOME}/bin/${APP_NAME}.unsigned.apk ${DEV_HOME}/bin && \ ${JAVA_HOME}/bin/jarsigner -verbose -keystore ${KEYSTORE} -storepass password -keypass password -signedjar ${DEV_HOME}/bin/${APP_NAME}.signed.apk ${DEV_HOME}/bin/${APP_NAME}.unsigned.apk AndroidTestKey && \ ${ANDROID_HOME}/build-tools/23.0.1/zipalign -v -f 4 ${DEV_HOME}/bin/${APP_NAME}.signed.apk ${DEV_HOME}/bin/${APP_NAME}.apk } function startVM() { ${ANDROID_HOME}/tools/emulator -wipe-data -avd ${AVD_NAME} & } function testApp() { #uninstall... ${ANDROID_HOME}/platform-tools/adb -e install -r ${DEV_HOME}/bin/${APP_NAME}.apk #read -p "Press enter to uninstall" #${ANDROID_HOME}/platform-tools/adb -e uninstall ${PACKAGE} #install on device #${ANDROID_HOME}/platform-tools/adb -d install ${DEV_HOME}/bin/${APP_NAME}.apk } function document() { ${JAVA_HOME}/bin/javadoc -verbose -d ${DEV_HOME}/docs -sourcepath ${DEV_HOME}/src -classpath ${ANDROID_HOME}/platforms/${TARGET}/android.jar;${DEV_HOME}/obj -author -package -use -splitIndex -version -windowtitle '${APP_NAME}' -doctitle '${APP_NAME}' ${DEV_HOME}/src/${PACKAGE_PATH}/*.java } function clean() { rm ${DEV_HOME}/bin/* rm -rf ${DEV_HOME}/obj/* find ${DEV_HOME}/src -name R.java -exec rm \{\} + }