2 # Quick semi-auto file to build Windows SDK tools.
5 # - Expects the emulator has been built first, will pick it up from prebuilt.
7 # - Needs Cygwin package zip
8 # - Expects to have one of the existing SDK (Darwin or Linux) to build the Windows one
10 set -e # Fail this script as soon as a command fails -- fail early, fail fast
12 # Set to 1 to force removal of old unzipped SDK. Only disable for debugging, as it
13 # will make some rm/mv commands to fail.
20 [ -z "$TEMP_DIR" ] && TEMP_DIR=${TMP:-/tmp}
30 NAME=`basename ${PROG_NAME}`
31 echo "Usage: ${NAME} linux_or_mac_sdk.zip output_dir [temp_dir]"
32 echo "If temp_dir is not given, \$TMP is used. If that's missing, /tmp is used."
38 echo "Current values:"
39 echo "- Input SDK: ${SDK_ZIP:-missing}"
40 echo "- Output dir: ${DIST_DIR:-missing}"
41 echo "- Temp dir: ${TEMP_DIR:-missing}"
45 [ -f "$SDK_ZIP" ] || usage
46 [ -d "$DIST_DIR" ] || usage
48 # Use the BUILD_ID as SDK_NUMBER if defined, otherwise try to get it from the
49 # provided zip filename.
50 if [ -f config/build_id.make ]; then
51 BUILD_ID=`cat config/build_id.make | sed -n '/BUILD_ID=/s/^[^=]\+=\(.*\)$/\1/p'`
52 [ -n "$BUILD_ID" ] && SDK_NUMBER="$BUILD_ID"
54 if [ -z "$SDK_NUMBER" ]; then
55 # Look for a pattern like "anything_sdknumber.extension"
56 # The pattern is now "any-thing_sdknumber_anything-else.extension"
58 # The bottom line is that the SDK number is whatever is enclosed by
59 # the LAST couple of underscores. You can have underscores *before* the
60 # SDK number if you want, but not after, e.g these are valid:
61 # android_sdk_4242_platform.zip or blah_42_.zip
63 # SDK_NUMBER will be empty if nothing matched.
64 filename=`basename "$SDK_ZIP"`
65 SDK_NUMBER=`echo $filename | sed -n 's/^.*_\([^_./]\+\)_[^_.]*\..*$/\1/p'`
68 [ -n "$SDK_NUMBER" ] || die "Failed to extract the SDK number from $SDK_ZIP. Check its format."
70 [ $OSTYPE == "cygwin" ] || die "This expects to run under Cygwin"
71 [ -e `which zip` ] || die "Please install 'zip' package in Cygwin"
72 [ -f "build/envsetup.sh" ] || die "Please run this from the 'android' directory"
74 echo "Using SDK ${SDK_NUMBER}"
81 [ -n "$MAKE_OPT" ] && echo "Make options: $MAKE_OPT"
83 make -j 4 emulator || die "Build failed"
84 # Disable parallel build: it generates "permission denied" issues when
85 # multiple "ar.exe" are running in parallel.
100 DEST_NAME="android-sdk_${SDK_NUMBER}_windows"
101 DEST_NAME_ZIP="${DEST_NAME}.zip"
103 TEMP_SDK_DIR="$TEMP_DIR/$DEST_NAME"
105 # Unzip current linux/mac SDK and rename using the windows name
106 if [[ -n "$FORCE" || ! -d "$TEMP_SDK_DIR" ]]; then
107 [ -e "$TEMP_SDK_DIR" ] && rm -rfv "$TEMP_SDK_DIR" # cleanup dest first if exists
108 UNZIPPED=`basename "$SDK_ZIP"`
109 UNZIPPED="$TEMP_DIR/${UNZIPPED/.zip/}"
110 [ -e "$UNZIPPED" ] && rm -rfv "$UNZIPPED" # cleanup unzip dir (if exists)
111 unzip "$SDK_ZIP" -d "$TEMP_DIR"
112 mv -v "$UNZIPPED" "$TEMP_SDK_DIR"
115 # Assert that the package contains only one platform
116 PLATFORMS="$TEMP_SDK_DIR/platforms"
117 THE_PLATFORM=`echo $PLATFORMS/*`
118 PLATFORM_TOOLS=$THE_PLATFORM/tools
119 echo "Platform found: " $THE_PLATFORM
120 [[ -d "$THE_PLATFORM" ]] || die \
121 "Error: One platform was expected in $SDK_ZIP. " \
122 "Instead found " $THE_PLATFORM
123 [[ -d "$PLATFORM_TOOLS" ]] || die "Missing folder $PLATFORM_TOOLS."
126 if type package_usb_driver 2>&1 | grep -q function ; then
127 package_usb_driver $TEMP_SDK_DIR
130 # Remove obsolete stuff from tools & platform
131 TOOLS="$TEMP_SDK_DIR/tools"
132 LIB="$TEMP_SDK_DIR/tools/lib"
133 rm -v "$TOOLS"/{adb,android,apkbuilder,ddms,dmtracedump,draw9patch,emulator}
134 rm -v "$TOOLS"/{hierarchyviewer,hprof-conv,mksdcard,sqlite3,traceview,zipalign}
135 rm -v "$LIB"/*/swt.jar
136 rm -v "$PLATFORM_TOOLS"/{aapt,aidl,dx,dexdump}
138 # Copy all the new stuff in tools
139 # Note: some tools are first copied here and then moved in platforms/<name>/tools/
140 cp -v out/host/windows-x86/bin/*.{exe,dll} "$TOOLS"/
142 cp -v prebuilt/windows/swt/swt.jar "$LIB"/x86/
143 mkdir -pv "$LIB"/x86_64
144 cp -v prebuilt/windows-x86_64/swt/swt.jar "$LIB"/x86_64/
146 # If you want the emulator NOTICE in the tools dir, uncomment the following line:
147 # cp -v external/qemu/NOTICE "$TOOLS"/emulator_NOTICE.txt
149 # We currently need libz from MinGW for aapt
150 cp -v /cygdrive/c/cygwin/bin/mgwz.dll "$TOOLS"/
152 # Update a bunch of bat files
153 cp -v development/tools/apkbuilder/etc/apkbuilder.bat "$TOOLS"/
154 cp -v development/tools/ddms/app/etc/ddms.bat "$TOOLS"/
155 cp -v development/tools/traceview/etc/traceview.bat "$TOOLS"/
156 cp -v development/tools/hierarchyviewer/etc/hierarchyviewer.bat "$TOOLS"/
157 cp -v development/tools/draw9patch/etc/draw9patch.bat "$TOOLS"/
158 cp -v development/tools/sdkmanager/app/etc/android.bat "$TOOLS"/
160 # Put the JetCreator tools, content and docs (not available in the linux SDK)
162 JETCREATOR="$JET/JetCreator"
163 JETDEMOCONTENT="$JET/demo_content"
164 JETLOGICTEMPLATES="$JET/logic_templates"
165 JETDOC="$TEMP_SDK_DIR/docs/JetCreator"
167 # need to rm these folders since a Mac SDK will have them and it might create a conflict
171 # now create fresh folders for JetCreator
175 cp -rv external/sonivox/jet_tools/JetCreator "$JETCREATOR"/
176 cp -rv external/sonivox/jet_tools/JetCreator_content "$JETDEMOCONTENT"/
177 cp -rv external/sonivox/jet_tools/logic_templates "$JETLOGICTEMPLATES"/
178 chmod -vR u+w "$JETCREATOR" # fixes an issue where Cygwin might copy the above as u+rx only
179 cp -v prebuilt/windows/jetcreator/EASDLL.dll "$JETCREATOR"/
181 cp -v external/sonivox/docs/JET_Authoring_Guidelines.html "$JETDOC"/
182 cp -rv external/sonivox/docs/JET_Authoring_Guidelines_files "$JETDOC"/
183 cp -v external/sonivox/docs/JET_Creator_User_Manual.html "$JETDOC"/
184 cp -rv external/sonivox/docs/JET_Creator_User_Manual_files "$JETDOC"/
186 # Copy or move platform specific tools to the default platform.
187 cp -v dalvik/dx/etc/dx.bat "$PLATFORM_TOOLS"/
188 mv -v "$TOOLS"/{aapt.exe,aidl.exe,dexdump.exe} "$PLATFORM_TOOLS"/
189 # Note: mgwz.dll must be both in SDK/tools for zipalign and in SDK/platform/XYZ/tools/ for aapt
190 cp -v "$TOOLS"/mgwz.dll "$PLATFORM_TOOLS"/
192 # Fix EOL chars to make window users happy - fix all files at the top level only
193 # as well as all batch files including those in platforms/<name>/tools/
194 find "$TEMP_SDK_DIR" -maxdepth 1 -type f -writable -print0 | xargs -0 unix2dos -D
195 find "$TEMP_SDK_DIR" -maxdepth 3 -name "*.bat" -type f -writable -print0 | xargs -0 unix2dos -D
197 # Done.. Zip it. Clean the temp folder ONLY if the zip worked (to ease debugging)
198 pushd "$TEMP_DIR" > /dev/null
199 [ -e "$DEST_NAME_ZIP" ] && rm -rfv "$DEST_NAME_ZIP"
200 zip -9r "$DEST_NAME_ZIP" "$DEST_NAME" && rm -rfv "$DEST_NAME"
203 # Now move the final zip from the temp dest to the final dist dir
204 mv -v "$TEMP_DIR/$DEST_NAME_ZIP" "$DIST_DIR/$DEST_NAME_ZIP"
206 # We want fastboot and adb (and its DLLs) next to the new SDK
207 for i in fastboot.exe adb.exe AdbWinApi.dll AdbWinUsbApi.dll; do
208 cp -vf out/host/windows-x86/bin/$i "$DIST_DIR"/$i
213 echo "Resulting SDK is in $DIST_DIR/$DEST_NAME_ZIP"