diff --git a/.gitignore b/.gitignore index 5241da1c5e..0b08529792 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ local.properties # sign.properties .DS_Store captures/ -build/ \ No newline at end of file +build/ +patch/ \ No newline at end of file diff --git a/app/tinker-support.gradle b/app/tinker-support.gradle index d62cadad0c..a622db65c2 100644 --- a/app/tinker-support.gradle +++ b/app/tinker-support.gradle @@ -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() /** * optional,default '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() /** * optional,default 'null' * It is nice to keep the resource id from R.txt file to reduce java changes */ - applyResourceMapping = getApplyResourceMappingPath() +// applyResourceMapping = getApplyResourceMappingPath() /** * necessary,default 'null' diff --git a/gradle.properties b/gradle.properties index c607e78583..de3db25dcd 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 \ No newline at end of file +# 请不要手动改动下面的值,除非你明确需要以某个apk作为基准包,需要打包请以scripts/tinker*.sh为准 +TINKER_ENABLE= +TINKER_BASE_APK_DIR=app-0915-15-00-01_6d009edd diff --git a/scripts/tinker_disable.sh b/scripts/tinker_disable.sh new file mode 100755 index 0000000000..d97fba2557 --- /dev/null +++ b/scripts/tinker_disable.sh @@ -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 \ No newline at end of file diff --git a/scripts/tinker_release_base.sh b/scripts/tinker_release_base.sh new file mode 100755 index 0000000000..951be8950c --- /dev/null +++ b/scripts/tinker_release_base.sh @@ -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 + + diff --git a/scripts/tinker_release_patch.sh b/scripts/tinker_release_patch.sh new file mode 100755 index 0000000000..c1848341e1 --- /dev/null +++ b/scripts/tinker_release_patch.sh @@ -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 + + +