Android应用多渠道打包脚本

使用ant打包Android程序时,请确保在项目根目录下包含build.xml,且文件中有声明项目名,最后在release目录下面会有我们想要的各种渠道包

#!/bin/sh
ANDROID_PROJECT_HOME="."

# get project name 
APPNAME=$(cat $ANDROID_PROJECT_HOME/build.xml | grep "\<project")
APPNAME=${APPNAME#*name=\"}
APPNAME=${APPNAME%%\"*}
echo "Project Name: $APPNAME"

MARKETS="qihoo360 yingyongbao baidu xiaomi wandoujia google"

echo "clear project"
rm -rf $ANDROID_PROJECT_HOME/bin/
rm -rf $ANDROID_PROJECT_HOME/gen/
rm -rf release/
echo "clear project finished"

mkdir release/
ant release -buildfile $ANDROID_PROJECT_HOME/build.xml &&
cp $ANDROID_PROJECT_HOME/bin/$APPNAME-release.apk release/$APPNAME.apk

echo "get the original market name"
market_bak=$(cat $ANDROID_PROJECT_HOME/AndroidManifest.xml | grep UMENG_CHANNEL)
market_bak=${market_bak#*value=\"}
market_bak=${market_bak%%\"*}
for market in $MARKETS
do
    echo "packaging ${APPNAME}_${market}.apk ..."
    sed -i "s#\(android:value=\)\"\(.*\)\"\( android:name=\"UMENG_CHANNEL\"\)#\1\"$market\"\3#" $ANDROID_PROJECT_HOME/AndroidManifest.xml
    ant release -buildfile $ANDROID_PROJECT_HOME/build.xml &&
    cp $ANDROID_PROJECT_HOME/bin/$APPNAME-release.apk release/${APPNAME}_$market.apk
done
echo recover the original market name
sed -i "s#\(android:value=\)\"\(.*\)\"\( android:name=\"UMENG_CHANNEL\"\)#\1\"$market_bak\"\3#" $ANDROID_PROJECT_HOME/AndroidManifest.xml

# install apk
adb install -r ./release/$APPNAME.apk

你可能感兴趣的:(android,ant,脚本)