Created
December 9, 2016 04:57
-
-
Save zhanghai/37fb12d12a90b30439b8ced1d1792dad to your computer and use it in GitHub Desktop.
Fix XML format of Material Design icon generation in Android Studio
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
ANDROID_LIB_PATH='/opt/android-studio/plugins/android/lib/' | |
TEMP_DIR='sdk-tools/' | |
TEMP_FILE='sdk-tools.jar' | |
if [[ -f "${ANDROID_LIB_PATH}/sdk-tools.jar.orig" ]]; then | |
echo "${ANDROID_LIB_PATH}/sdk-tools.jar.orig already exists, exiting..." >&2 | |
exit 1 | |
fi | |
if [[ -d "${TEMP_DIR}" ]]; then | |
echo "${TEMP_DIR} already exists, exiting..." >&2 | |
exit 2 | |
fi | |
if [[ -d "${TEMP_FILE}" ]]; then | |
echo "${TEMP_FILE} already exists, exiting..." >&2 | |
exit 3 | |
fi | |
mkdir "${TEMP_DIR}" | |
cd "${TEMP_DIR}" | |
echo "Extracting..." >&2 | |
jar xf "${ANDROID_LIB_PATH}/sdk-tools.jar" | |
echo "Fixing..." >&2 | |
find images/material_design_icons/ -type f -exec sed -i \ | |
-e '1s|^|<?xml version="1.0" encoding="utf-8"?>\n\n|' \ | |
-e 's|<vector xmlns:android="http://schemas.android.com/apk/res/android"|<vector\n xmlns:android="http://schemas.android.com/apk/res/android"|' \ | |
-e 's| android:width="24dp"| android:width="24dp"|' \ | |
-e 's| android:height="24dp"| android:height="24dp"|' \ | |
-e 's| android:viewportWidth="24.0"| android:viewportWidth="24"|' \ | |
-e 's| android:viewportHeight="24.0">| android:viewportHeight="24">|' \ | |
-e 's| <path|\n <path|' \ | |
-e 's|"/>|" />|' \ | |
{} \; | |
echo "Packaging..." >&2 | |
jar cf "../${TEMP_FILE}" * | |
cd .. | |
rm -r "${TEMP_DIR}" | |
echo "Installing..." >&2 | |
sudo mv "${ANDROID_LIB_PATH}/sdk-tools.jar" "${ANDROID_LIB_PATH}/sdk-tools.jar.orig" | |
sudo mv "${TEMP_FILE}" "${ANDROID_LIB_PATH}/sdk-tools.jar" | |
sudo chown root:root "${ANDROID_LIB_PATH}/sdk-tools.jar" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment