add tinker scripts

This commit is contained in:
CsHeng
2017-09-15 15:24:44 +08:00
parent 6d009eddf5
commit 48e3718fc2
6 changed files with 182 additions and 13 deletions

3
.gitignore vendored
View File

@ -5,4 +5,5 @@ local.properties
# sign.properties
.DS_Store
captures/
build/
build/
patch/

View File

@ -3,12 +3,7 @@ def bakPath = file("${buildDir}/bakApk/")
/**
* 此处填写每次构建生成的基准包目录
*/
def baseApkDir = "app-0913-16-52-48"
ext {
//for some reason, you may want to ignore tinkerBuild, such as instant run debug build?
tinkerEnabled = false
}
def baseApkDir = hasProperty("TINKER_BASE_APK_DIR") ? TINKER_BASE_APK_DIR : ""
def gitSha() {
try {
@ -27,7 +22,7 @@ def getTinkerIdValue() {
}
def buildWithTinker() {
return hasProperty("TINKER_ENABLE") ? TINKER_ENABLE : ext.tinkerEnabled
return hasProperty("TINKER_ENABLE") ? TINKER_ENABLE : false
}
if (buildWithTinker()) {
@ -67,7 +62,7 @@ if (buildWithTinker()) {
buildAllFlavorsDir = "${bakPath}/${baseApkDir}"
// 是否启用加固模式默认为false.(tinker-spport 1.0.7起支持)
// isProtectedApp = true
isProtectedApp = false
// 是否开启反射Application模式
enableProxyApplication = false
@ -85,7 +80,7 @@ if (buildWithTinker()) {
* the old apk path, use to diff with the new apk to build
* add apk from the build/bakApk
*/
oldApk = getOldApkPath()
// oldApk = getOldApkPath()
/**
* optionaldefault 'false'
* there are some cases we may get some warnings
@ -221,12 +216,12 @@ if (buildWithTinker()) {
* Warning:
* you must be careful that it will affect the normal assemble build!
*/
applyMapping = getApplyMappingPath()
// applyMapping = getApplyMappingPath()
/**
* optionaldefault 'null'
* It is nice to keep the resource id from R.txt file to reduce java changes
*/
applyResourceMapping = getApplyResourceMappingPath()
// applyResourceMapping = getApplyResourceMappingPath()
/**
* necessarydefault 'null'

View File

@ -58,4 +58,6 @@ COMMENT_HOST=http\://api.ghzs.com/v3d0/
DATA_HOST=http\://data.ghzs666.com/
USERSEA_HOST=https\://usersea.ghzs.com/v1d0/
#TINKER_ENABLED=1
# 请不要手动改动下面的值除非你明确需要以某个apk作为基准包需要打包请以scripts/tinker*.sh为准
TINKER_ENABLE=
TINKER_BASE_APK_DIR=app-0915-15-00-01_6d009edd

22
scripts/tinker_disable.sh Executable file
View File

@ -0,0 +1,22 @@
#!/usr/bin/env bash
# *****************************************************************************
# @author CsHeng
# @2017.9.14 init
#
# 简单禁用tinker标志位
#
#
# *****************************************************************************
# get current shell absolute dir
CWD=$(cd "$(dirname "$0")"; pwd)
GRADLE_FILE=${CWD}/../gradle.properties
echo "disable gradle file tinker vals..."
# disable tinker build
sed -i.bak "s/TINKER_ENABLE\=\(.*\)/TINKER_ENABLE\=/g" ${GRADLE_FILE}
# remove tmp files
rm ${GRADLE_FILE}.bak

79
scripts/tinker_release_base.sh Executable file
View File

@ -0,0 +1,79 @@
#!/usr/bin/env bash
# *****************************************************************************
# @author CsHeng
# @2017.9.14 init
#
# 处理tinker打包的事情
# 1、启用tinker标志位
# 2、打出基线包修改tinker base apk path
# 3、禁用tinker标志位
#
# *****************************************************************************
# get current shell absolute dir
CWD=$(cd "$(dirname "$0")"; pwd)
GRADLE_FILE=${CWD}/../gradle.properties
BAK_APK_DIR=${CWD}/../app/build/bakApk/
PATCH_BACKUP=${CWD}/../patch/
# 如果git代码已经提交了目的是为了确认git commit id是能作为一个可追踪的tinkerId
status=`cd ${CWD} && git status | grep up-to-date | wc -l && cd ${OLDPWD}`
if [ ${status} -eq 0 ]; then
echo "Please make sure that you commit your code before release "
exit 0
fi
path_dir=`grep -r TINKER_BASE_APK_DIR ${GRADLE_FILE}| awk -F '=' '{print $2}'`
path_base=`echo ${path_dir} | awk -F '_' '{print $1}'`
git_sha_new=`git rev-parse --short HEAD`
git_sha_old=`echo ${path_dir} | awk -F '_' '{print $2}'`
if [ "${git_sha_new}" == "${git_sha_old}" ]; then
echo "new git sha same as old git sha, skip patch."
exit 0
fi
echo "enabling tinker..."
# enable tinker build
sed -i.bak "s/TINKER_ENABLE\=\(.*\)/TINKER_ENABLE\=1/g" ${GRADLE_FILE}
echo "recompiling gradle scripts..."
${CWD}/../gradlew --recompile-scripts
echo "gradle assembleRelease..."
# 由于我们可能在内部发布的时候也使用这个工具所以不知道具体release哪个索性一次性release掉
${CWD}/../gradlew assembleRelease --parallel
# 然后app/build/bakApk/会有一个文件夹保存基线包版本的所有文件这些文件是需要保存起来的以便出bug的时候
# 由于默认的tinker support产生文件的规则都是以时间来判断的那么我们做个排序拿最新的为准
# get apk dir name
oldAppDir=`ls -t ${BAK_APK_DIR} | head -1`
git_sha=`git rev-parse --short HEAD`
dest_dir=${oldAppDir}_${git_sha}
echo "saving patch base files...to ${dest_dir}"
mkdir -p ${PATCH_BACKUP}/${dest_dir}
cp -r ${BAK_APK_DIR}/${oldAppDir}/ ${PATCH_BACKUP}/${dest_dir}
echo "disabling tinker & set release old apk path"
sed -i.bak "s/TINKER_ENABLE\=\(.*\)/TINKER_ENABLE\=/g" ${GRADLE_FILE}
# apk path
sed -i.bak "s/TINKER_BASE_APK_DIR\=\(.*\)/TINKER_BASE_APK_DIR\=${dest_dir}/g" ${GRADLE_FILE}
# remove tmp file
rm ${GRADLE_FILE}.bak
echo "recompiling gradle scripts..."
${CWD}/../gradlew --recompile-scripts

70
scripts/tinker_release_patch.sh Executable file
View File

@ -0,0 +1,70 @@
#!/usr/bin/env bash
# *****************************************************************************
# @author CsHeng
# @2017.9.13 init
#
# 处理tinker patch包默认以最新的包作为基线包来出包
#
#
# *****************************************************************************
# get current shell absolute dir
CWD=$(cd "$(dirname "$0")"; pwd)
GRADLE_FILE=${CWD}/../gradle.properties
BAK_APK_DIR=${CWD}/../app/build/bakApk/
PATCH_OUTPUT=${BAK_APK_DIR}/../outputs/patch/
PATCH_BACKUP=${CWD}/../patch/
# 如果git代码已经提交了目的是为了确认git commit id是能作为一个可追踪的tinkerId
status=`cd ${CWD} && git status | grep up-to-date | wc -l && cd ${OLDPWD}`
if [ ${status} -eq 0 ]; then
echo "Please make sure that you commit your code before release "
exit 0
fi
path_dir=`grep -r TINKER_BASE_APK_DIR ${GRADLE_FILE}| awk -F '=' '{print $2}'`
path_base=`echo ${path_dir} | awk -F '_' '{print $1}'`
git_sha_new=`git rev-parse --short HEAD`
git_sha_old=`echo ${path_dir} | awk -F '_' '{print $2}'`
echo ${path_dir} ${path_base} ${git_sha_old} ${git_sha_new}
if [ "${git_sha_new}" == "${git_sha_old}" ]; then
echo "new git sha same as old git sha, skip patch."
exit 0
fi
echo "enabling tinker..."
# enable tinker build
sed -i.bak "s/TINKER_ENABLE\=\(.*\)/TINKER_ENABLE\=1/g" ${GRADLE_FILE}
echo "recompiling gradle scripts..."
${CWD}/../gradlew --recompile-scripts
mkdir -p ${BAK_APK_DIR}/${path_dir}
cp -r ${PATCH_BACKUP}/${path_dir}/ ${BAK_APK_DIR}/${path_dir}
echo "releasing patch... gradle buildAllFlavorsTinkerPatchRelease..."
${CWD}/../gradlew buildAllFlavorsTinkerPatchRelease --parallel
echo "copying back patch files in case that files have been cleaned..."
dest_dir=${PATCH_BACKUP}/${path_dir}/${git_sha_new}
mkdir -p ${dest_dir}
cp -r ${PATCH_OUTPUT}/ ${dest_dir}
echo "disabling tinker"
sed -i.bak "s/TINKER_ENABLE\=\(.*\)/TINKER_ENABLE\=/g" ${GRADLE_FILE}
# remove tmp file
rm ${GRADLE_FILE}.bak
echo "recompiling gradle scripts..."
${CWD}/../gradlew --recompile-scripts