把编译信息放在 Launch Icon 上

enter image description here|center
首先上一张效果吧!这是我们CI集成测试包后 icon。在icon上分别显示了版本号、build 时间、git id。

如何实现的呢?看下面。

首先,我们要有 ghostscriptimagemagick 两个环境。

brew install ghostscript
brew install imagemagick

其次,在编译 apk 之前,执行下面的 shell,就会主动替换为新icon。

#!/usr/bin/env bash
#引入环境变量
export PATH=$PATH:/usr/local/bin
#读取版本name
source $WORKSPACE/gradle.properties
shortVersion=${VERSION_NAME}
#编译时间
createDate=`date +%m%d_%H:%M`
#获取git id
commit=`git rev-parse --short HEAD`
bundleVersion=`git rev-list HEAD | wc -l | awk '{print $1}'`
#获取icon路径数组
resPath="$WORKSPACE/android-autoEasy/src/main/res"

mdpiPath="${resPath}/drawable-mdpi/icon.png"
hdpiPath="${resPath}/drawable-hdpi/icon.png"
xhdpiPath="${resPath}/drawable-xhdpi/icon.png"
xxhdpiPath="${resPath}/drawable-xxhdpi/icon.png"
iconPaths=(${mdpiPath} ${hdpiPath} ${xhdpiPath} ${xxhdpiPath})

echo
echo "*********************************************"
echo "* ${shortVersion}_${bundleVersion}_${commit}"
echo "*********************************************"
echo
#把信息写到icon上
function processIcon() {
    pngPath=$1

    echo
    echo "*********************************************"
    echo "* start ---> ${pngPath}"
    echo "*********************************************"
    echo

    echo "from -> ${pngPath}"

    if [[ ! -f ${pngPath} ]]; then
    echo "can't find ${pngPath} "
    return;
    fi

    target_path=${pngPath}

    echo "to -> ${target_path}"

    width=`identify -format %w ${pngPath}`
    echo "width = $width"

    string=$"\n"
    `echo convert -background '#0008' -fill white -gravity center -size ${width}x${width} \
    caption:"${shortVersion}${string}${createDate}${string}${commit}" \
    ${pngPath} +swap -gravity south -composite ${target_path}`

    echo "name = ${shortVersion}${string}${createDate}${string}${commit}"

    echo
    echo "*********************************************"
    echo "* end <--- ${pngPath}"
    echo "*********************************************"
    echo
}

#判断是否已经安装了必须工具 imagemagick ghostscript
echo `brew ls` |grep -q "imagemagick"
if [ $? -eq 0 ]; then
    echo "imagemagick installed "

    echo `brew ls` |grep -q "ghostscript"
    if [ $? -eq 0 ]; then
        echo "ghostscript installed "

        for paths in ${iconPaths[@]}
        do
            processIcon ${paths}
        done

    fi
fi
echo
echo "*********************************************"
echo "* run script end"
echo "*********************************************"
echo

最后,就是编译 apk 啦!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值