Skip to content

Instantly share code, notes, and snippets.

@andaag
Forked from dextorer/strip.conf
Last active August 29, 2015 14:07
Show Gist options
  • Save andaag/80892292638e02159fb1 to your computer and use it in GitHub Desktop.
Save andaag/80892292638e02159fb1 to your computer and use it in GitHub Desktop.
actions=true
ads=true
analytics=true
appindexing=true
appstate=true
auth=true
cast=true
common=true
drive=false
dynamic=true
games=false
gcm=true
identity=true
internal=true
location=false
maps=false
panorama=false
plus=true
security=true
tagmanager=true
wallet=false
wearable=true
#!/bin/sh
#
# Strips the Google Play Services JAR archive and removes the folders that are specified below.
# This should lower the methods count of the final DEX file and should lower the chance of hitting
# the (dreaded) 64K methods limit.
#
#
# Author: Sebastiano Gottardo
# @rotxed - dextorer[at]gmail[dot]com
#
# Hacked to modify and create an aar by Anders Aagaard <[email protected]>
echo "Using $ANDROID_HOME as sdk root path"
VERSION="5.0.89"
INPUT="${ANDROID_HOME}extras/google/m2repository/com/google/android/gms/play-services/5.0.89/play-services-${VERSION}.aar"
PLAY_SERVICES_FILENAME="classes.jar"
PLAY_SERVICES_TEMP_DIR="google-play-services-temp"
PLAY_SERVICES_STRIP_FILE="strip.conf"
PLAY_SERVICES_NESTED_PATH="com/google/android/gms"
# Preventive cleanup
rm -rf $PLAY_SERVICES_TEMP_DIR
mkdir $PLAY_SERVICES_TEMP_DIR || exit 1
cp $PLAY_SERVICES_STRIP_FILE $PLAY_SERVICES_TEMP_DIR
cd $PLAY_SERVICES_TEMP_DIR || exit 1
unzip $INPUT || exit 1
# Create temporary work folder
mkdir tmp
cp $PLAY_SERVICES_FILENAME tmp || exit 1
cd tmp || exit 1
# Extract the content of the Play Services JAR archive
echo "Extracting archive, please wait.."
jar xvf $PLAY_SERVICES_FILENAME > /dev/null || exit 1
echo "Extracted.\n"
# If the configuration file doesn't exist, create it
if [ ! -f ../$PLAY_SERVICES_STRIP_FILE ]; then
# Create the file
touch ../$PLAY_SERVICES_STRIP_FILE
FOLDERS=`ls $PLAY_SERVICES_NESTED_PATH`
for index in $FOLDERS
do
echo "$index=true" >> ../$PLAY_SERVICES_STRIP_FILE
done
fi
# Read configuration from file
while read -r FOLDERS
do
CURRENT_FOLDER=$FOLDERS
CURRENT_FOLDER_NAME=`echo $CURRENT_FOLDER | awk -F'=' '{print $1}'`
CURRENT_FOLDER_ENABLED=`echo $CURRENT_FOLDER | awk -F'=' '{print $2}'`
if [ "$CURRENT_FOLDER_ENABLED" = false ]; then
echo "Removed $CURRENT_FOLDER_NAME folder"
rm -rf "$PLAY_SERVICES_NESTED_PATH/$CURRENT_FOLDER_NAME"
else
echo "Keeeping $CURRENT_FOLDER_NAME folder"
fi
done < ../"$PLAY_SERVICES_STRIP_FILE"
# Create final stripped JAR
jar cf tmp.jar com/ || exit 1
mv tmp.jar ../classes.jar || exit 1
cd ..
# Clean up
echo "\nFolders removed, cleaning up.."
rm -rf tmp
zip -r play-services.aar * || exit 1
mv play-services.aar .. || exit 1
echo "Created play-services.aar"
cd ..
rm -rf $PLAY_SERVICES_TEMP_DIR
echo "All done, exiting!"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment