1 #!/bin/bash 2 3 set -e 4 5 usage() { 6 7 cat <<EOF 8 $0 9 --sdk <SDK file path> 10 --system <system sdk file path> 11 --support <support library file path> 12 EOF 13 exit 2 14 15 } 16 17 banner() { 18 echo "**************************************************" 19 echo "Updating $1 " 20 echo "**************************************************" 21 } 22 23 update_sdk() { 24 if [ -f "$SDK" ] 25 then 26 banner "SDK" 27 cd $ROOT_DIR/current 28 rm -f android.jar uiautomator.jar framework.aidl 29 unzip -j $SDK */android.jar */uiautomator.jar */framework.aidl 30 fi 31 } 32 33 update_system_sdk() { 34 if [ -f "$SYSTEM_SDK" ] 35 then 36 banner "system SDK" 37 cp -f $SYSTEM_SDK $ROOT_DIR/system_current/android.jar 38 fi 39 } 40 41 update_support_lib() { 42 if [ -f "$SUPPORT" ] 43 then 44 banner "support library" 45 rm -rf $ROOT_DIR/current/support/ 46 cd $ROOT_DIR/current 47 unzip $SUPPORT >/dev/null 48 49 # Remove duplicates 50 rm -f support/v7/appcompat/libs/android-support-v4.jar 51 rm -f support/multidex/instrumentation/libs/android-support-multidex.jar 52 53 # Remove samples 54 rm -rf support/samples 55 56 # Remove source files 57 find support -name "*.java" \ 58 -o -name "*.aidl" \ 59 -o -name AndroidManifest.xml \ 60 | xargs rm 61 62 # Other misc files we don't need 63 find support -name "*.gradle" \ 64 -o -name ".classpath" \ 65 -o -name ".project" \ 66 -o -name "project.properties" \ 67 -o -name "source.properties" \ 68 -o -name ".readme" \ 69 -o -name "README.txt" \ 70 -o -name "package.html" \ 71 -o -name "NOTICE.txt" \ 72 | xargs rm 73 74 # Now we can remove empty dirs 75 find . -type d -empty -delete 76 fi 77 } 78 79 main() { 80 while [ "$#" -gt 0 ] 81 do 82 case "$1" in 83 --help|-h) 84 usage 85 ;; 86 --sdk) 87 export SDK="$2" 88 shift; shift 89 ;; 90 --system) 91 export SYSTEM_SDK="$2" 92 shift; shift 93 ;; 94 --support) 95 export SUPPORT="$2" 96 shift; shift 97 ;; 98 -*) 99 usage 100 ;; 101 *) 102 break 103 ;; 104 esac 105 done 106 107 ROOT_DIR=$(realpath $(dirname $0)) 108 109 update_sdk 110 update_system_sdk 111 update_support_lib 112 } 113 114 main $* 115