Last active
August 29, 2015 14:05
-
-
Save nolanlawson/4f63c0fccb49498bb2ca to your computer and use it in GitHub Desktop.
Recompile just the assets in an Android APK. Faster than `gradle installDebug` if you're just modifying HTML/CSS/JS.
This file contains 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 | |
# | |
# Recompile Android assets into a -debug.apk. Assumes you have apktool | |
# installed and it's globally accessible as "apktool". | |
# | |
# Usage: ./recompile_assets.sh [path/to/debug.apk] [path/to/assets] | |
# | |
# If you don't include any arguments, it will try to determine the | |
# location of your assets/apk using the current working directory. | |
# | |
# This script currently doesn't do any merging of assets, so hopefully | |
# you have them all in src/main/assets. | |
# | |
# On Gist at https://gist.github.com/nolanlawson/4f63c0fccb49498bb2ca | |
# | |
APK_FILE=$1 | |
ASSETS=$2 | |
if [[ -z $APK_FILE ]]; then | |
APK_FILE=`find . | grep '\-debug\.apk$' | head -n 1` | |
fi | |
if [[ -z $ASSETS ]]; then | |
ASSETS=`find . | grep src/main/assets$` | |
fi | |
if [[ -z $APK_FILE ]]; then | |
echo -e "\nCouldn't find the debug.apk file" | |
exit 1 | |
fi | |
if [[ -z $ASSETS ]]; then | |
echo -e "\nCouldn't find the assets file" | |
exit 1 | |
fi | |
if [[ ! -x `which apktool` ]]; then | |
echo -e "\nCouldn't find apktool. Install it and make it globally accessible as 'apktool' please!" | |
echo "https://code.google.com/p/android-apktool/downloads/list" | |
exit 1 | |
fi | |
echo -e "\nUsing apk file: $APK_FILE" | |
echo "Using assets dir: $ASSETS" | |
echo -e "\nDecompiling..." | |
RANDO=$RANDOM | |
TMPDIR=/tmp/apktool-$RANDO | |
apktool d $APK_FILE $TMPDIR | |
echo -e "\nCopying over assets..." | |
rm -fr $TMPDIR/assets | |
cp -r $ASSETS $TMPDIR/assets | |
echo -e "\nRecompiling..." | |
apktool b $TMPDIR $APK_FILE | |
echo -e "\nSigning..." | |
jarsigner $APK_FILE androiddebugkey -digestalg SHA1 -sigalg MD5withRSA -keystore ~/.android/debug.keystore -keypass android -storepass android | |
echo -e "\nDone!\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment