Created
November 14, 2013 15:06
Script for creating and building several android app build from single template app. Data for every app should be provided in csv file.
Script creates new branch for every app, replaces necessary images (logos, icons, splash screens etc), makes changes in source files (change ids, names, colors etc), renames app, builds it and places final signe…
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 | |
# path to project dir | |
base_path=/home/username/apps/android_template/ | |
# path to main app project | |
proj_path=${base_path}MainActivity/ | |
# path to res dir | |
res_path=${proj_path}res/ | |
# path to dir with images for all necessary branches | |
img_path=/home/username/apps/images/ | |
#path to csv file with text info fo all branches | |
inputfile=${base_path}teams_data.csv | |
last=`tail -c 1 ${inputfile}` | |
if [[ $last != "" ]]; then echo "NO NEWLINE IN CSV!"; exit 0; fi | |
# default csv delimiter is comma, we'll save it and restore later | |
OLDIFS=$IFS | |
IFS=";" | |
# start reading csv from second line. First line is for headers | |
tail -n +2 ${inputfile}|while read rusname tag linkcolor gitname # and all other headers | |
do | |
branch_name="v1.0/${gitname}" # separate different versions | |
git checkout base_template # base template for all branches (apps) | |
git checkout -b $branch_name | |
# copy images for current branch | |
local_img=$img_path${gitname} | |
cp -R $local_img/drawable-hdpi $res_path | |
cp -R $local_img/drawable-mdpi $res_path | |
cp -R $local_img/drawable-xhdpi $res_path | |
# replace different strings in src files | |
lw=${gitname,,} # if you need lowercase value | |
lw2=${lw//[_]/} # if you need lowercase value with stripped _ symbol | |
sed -i -e "s/teamname/${rusname}/g" ${res_path}values/strings.xml | |
sed -i -e "s/TeamColor\">#000000/TeamColor\">#${linkcolor}/g" ${res_path}values/colors.xml | |
# etc... | |
# if you need to do something special for special branches | |
if [[ $gitname == 'team_a' || $gitname == 'team_b' ]]; then | |
sed -i -e "s/CATEGORY_ID\ =\ FOOTBALL/CATEGORY_ID\ =\ HOCKEY/g" ${proj_path}src/ru/xxx/api/DEFAULTS.java | |
fi | |
# trick for android app rename. test.patch must be created beforehand. | |
# HowTo: 1) Eclypse->Android Tools->Rename Application Package | |
# 2) git diff > ../test.patch | |
# 3) you have pattern for your app rename. Profit! | |
# And now all you have to do for every branch - replace template's 'newname' with app name for current branch | |
cp ${base_path}test.patch ${base_path}${lw}.patch | |
sed -i "s/newname/${lw}/g" ${base_path}${lw}.patch | |
# apply the patch | |
patch -p1 < ${base_path}${lw}.patch | |
# maybe it's not necessary - Eclypse sometimes ignore some places in AndroidManifest | |
sed -i -e "s/base\_template/${lw}/g" ${proj_path}AndroidManifest.xml | |
# build | |
# copy *.properties files - if you don't want to save them in git | |
cp ${base_path}project.properties ${proj_path} | |
cp ${base_path}ant.properties ${proj_path} | |
# update project properties and set appropriate app name | |
android update project --target android-17 --name ru.xxx.${lw} --path . | |
ant clean | |
ant release | |
# if you don't want to save them in git | |
rm ${proj_path}build.xml | |
rm ${proj_path}ant.properties | |
# successful build should end with ready apk file | |
if [ -f ${proj_path}bin/ru.xxx.${lw}-release.apk ]; | |
then | |
cp ${proj_path}bin/ru.xxx.${lw}-release.apk ${base_path}ready/ | |
git add . && git commit -m 'new branch' && git push origin $branch_name | |
else | |
echo "Error while building app for ${gitname}!" | |
break # not exit 0 because we'd like to restore comma as delimiter | |
fi | |
done | |
# switch to default csv delimiter | |
IFS=$OLDIFS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment