Android热更新框架Tinker探索之旅文档格式.docx
- 文档编号:22886355
- 上传时间:2023-02-05
- 格式:DOCX
- 页数:42
- 大小:179.33KB
Android热更新框架Tinker探索之旅文档格式.docx
《Android热更新框架Tinker探索之旅文档格式.docx》由会员分享,可在线阅读,更多相关《Android热更新框架Tinker探索之旅文档格式.docx(42页珍藏版)》请在冰豆网上搜索。
tinker-android-anno:
//tinker依赖版本
compile("
tinker-android-lib:
)
2.tinker的一些配置
//-------------------------tinkerconfigstart-------------------------
buildConfigField"
String"
"
TINKER_VERSION"
\"
1.7.7\"
"
/**
*buildConfigcanchangeduringpatch!
*wecanusethenewlyvaluewhenpatch
*/
"
MESSAGE"
Iamthebaseapk\"
*clientversionwouldupdatewithpatch
*sowecangetthenewlygitversioneasily!
TINKER_ID"
${getTinkerIdValue()}\"
PLATFORM"
all\"
//-------------------------tinkerconfigend-------------------------
3.编译差分包的开关和老版本文件位置确定
defbakPath=file("
${buildDir}/bakApk/"
/**
*youcanuseassembleReleasetobuildyoubaseapk
*usetinkerPatchRelease-POLD_APK=-PAPPLY_MAPPING=-PAPPLY_RESOURCE=tobuildpatch
*addapkfromthebuild/bakApk
ext{
defoldPrefixFormat="
app_beta1_${appVersionName}_${newDate().format("
yyyy_MM_dd"
)}_%s_build${appVersionCode}_%s"
defoldApkPath=String.format(oldPrefixFormat,"
10_34_38"
tinker.apk"
defapplyMappingPath=String.format(oldPrefixFormat,"
mapping.txt"
defresourcePath=String.format(oldPrefixFormat,"
R.txt"
//forsomereason,youmaywanttoignoretinkerBuild,suchasinstantrundebugbuild?
tinkerEnabled=true
//fornormalbuild
//oldapkfiletobuildpatchapk
tinkerOldApkPath="
${bakPath}/${oldApkPath}"
//proguardmappingfiletobuildpatchapk
tinkerApplyMappingPath="
${bakPath}/${applyMappingPath}"
//resourceR.txttobuildpatchapk,mustinputifthereisresourcechanged
tinkerApplyResourcePath="
${bakPath}/${resourcePath}"
//onlyuseforbuildallflavor,ifnot,justignorethisfield
tinkerBuildFlavorDirectory="
${bakPath}/app-patch-${releaseTime()}"
}
4.tinker编译差分包的task配置
tinkerPatch{
*necessary,default'
null'
*theoldapkpath,usetodiffwiththenewapktobuild
oldApk=getOldApkPath()
*optional,default'
false'
*therearesomecaseswemaygetsomewarnings
*ifignoreWarningistrue,wewouldjustassertthepatchprocess
*case1:
minSdkVersionisbelow14,butyouareusingdexModewithraw.
*itmustbecrashwhenload.
*case2:
newlyaddedAndroidComponentinAndroidManifest.xml,
*case3:
loaderclassesindex.loader{}arenotkeepinthemaindex,
*itmustbelettinkernotwork.
*case4:
loaderclassesindex.loader{}changes,
*loaderclassesisuestoloadpatchdex.itisuselesstochangethem.
*itwon'
tcrash,butthesechangescan'
teffect.youmayignoreit
*case5:
resources.arschaschanged,butwedon'
tuseapplyResourceMappingtobuild
ignoreWarning=false
true'
*whethersignthepatchfile
*ifnot,youmustdoyourself.otherwiseitcan'
tchecksuccessduringthepatchloading
*wewillusethesignconfigwithyourbuildtype
useSign=true
*whetherusetinkertobuild
tinkerEnable=buildWithTinker()
*Warning,applyMappingwillaffectthenormalandroidbuild!
buildConfig{
*ifweusetinkerPatchtobuildthepatchapk,you'
dbettertoapplytheold
*apkmappingfileifminifyEnabledisenable!
*Warning:
*youmustbecarefulthatitwillaffectthenormalassemblebuild!
applyMapping=getApplyMappingPath()
*ItisnicetokeeptheresourceidfromR.txtfiletoreducejavachanges
applyResourceMapping=getApplyResourceMappingPath()
*becausewedon'
twanttocheckthebaseapkwithmd5intheruntime(itisslow)
*tinkerIdisusetoidentifytheuniquebaseapkwhenthepatchistriedtoapply.
*wecanusegitrev,svnrevorsimplyversionCode.
*wewillgenthetinkerIdinyourmanifestautomatic
tinkerId=getTinkerIdValue()
*ifkeepDexApplyistrue,classinwhichdexrefertotheoldapk.
*openthiscanreducethedexdifffilesize.
keepDexApply=false
dex{
jar'
*onlycanbe'
raw'
or'
.forraw,wewouldkeepitsoriginalformat
*forjar,wewouldrepackdexeswithzipformat.
*ifyouwanttosupportbelow14,youmustusejar
*oryouwanttosaveromorcheckquicker,youcanuserawmodealso
dexMode="
jar"
[]'
*whatdexesinapkareexpectedtodealwithtinkerPatch
*itsupport*or?
pattern.
pattern=["
classes*.dex"
"
assets/secondary-dex-?
.jar"
]
*Warning,itisveryveryimportant,loaderclassescan'
tchangewithpatch.
*thus,theywillberemovedfrompatchdexes.
*youmustputthefollowingclassintomaindex.
*Simply,youshouldaddyourownapplication{@codetinker.sample.android.SampleApplication}
*owntinkerLoader,andtheclassesyouuseinthem
*
loader=[
//usesample,letBaseBuildInfounchangeablewithtinker
com.simpletour.client.tinker.app.BaseBuildInfo"
]
lib{
*whatlibraryinapkareexpectedtodealwithtinkerPatch
*forlibraryinassets,wewouldjustrecovertheminthepatchdirectory
*youcangettheminTinkerLoadResultwithTinker
lib/*/*.so"
res{
*whatresourceinapkareexpectedtodealwithtinkerPatch
*youmustincludeallyourresourcesinapkhere,
*otherwise,theywon'
trepackinthenewapkresources.
res/*"
assets/*"
resources.arsc"
AndroidManifest.xml"
*theresourcefileexcludepatterns,ignoreadd,deleteormodifyresourcechange
*Warning,wecanonlyuseforfilesnorelativewithresources.arsc
ignoreChange=["
assets/sample_meta.txt"
*default100kb
*formodifyresource,ifitislargerthan'
largeModSize'
*wewouldliketousebsdiffalgorithmtoreducepatchfilesize
largeModSize=100
packageConfig{
TINKER_ID,TINKER_ID_VALUE'
'
NEW_TINKER_ID,NEW_TINKER_ID_VALUE'
*packagemetafilegen.pathisassets/package_meta.txtinpatchfile
*youcanusesecurityCheck.getPackageProperties()inyourownPackageCheckmethod
*orTinkerLoadResult.getPackageConfigByName
*wewillgettheTINKER_IDfromtheoldapkmanifestforyouautomatic,
*otherconfigfiles(suchaspatchMessagebelow)isnotnecessary
configField("
patchMessage"
tinkerissampletouse"
*justasamplecase,youcanusesuchassdkVersion,brand,channel...
*youcanparseitintheSamplePatchListener.
*Thenyoucanusepatchconditional!
platform"
all"
*patchversionviapackageConfig
patchVersion"
1.0"
//oryoucanaddconfigfiledoutside,orgetmetavaluefromoldapk
//project.tinkerPatch.packageConfig.configField("
test1"
project.tinkerPatch.packageConfig.getMetaDataFromOldApk("
Test"
))
test2"
sample"
*ifyoudon'
tusezipArtifactorpath,wejustuse7zatotry
sevenZip{
7za'
*the7zipartifactpath,itwillusetheright7zawithyourplatform
zipArtifact="
com.tencent.mm:
SevenZip:
1.1.10"
*youcanspecifythe7zapathyourself,itwilloverwritethezipArtifactvalue
//path="
/usr/local/bin/7za"
5.拷贝和自定义apk、mapping、R文件的别名
*bakapkandmapping
android.applicationVariants.all{variant->
*tasktype,youwanttobak
deftaskName=variant.name
defdate=newDate().format("
yyyy_MM_dd_HH_mm_ss"
defbuildTypeName=variant.baseName+"
defisRelease=buildTypeName=="
release"
tasks.all{
if("
assemble${taskName.capitalize()}"
.equalsIgnoreCase(it.name)){
it.doLast{
copy{
//正常情况下生成的apk文件的文件名前缀
deffileNamePrefix="
${project.name}-${buildTypeName}"
//自定义apk文件的别名
defnewFileNamePrefix="
app_beta1_${isRelease?
${buildTypeName}_"
:
}${appVersionName}_${date}_build${appVersionCode}"
//自定义apk、mapping、R文件存放的目录
defdestPath=hasFlavors?
file("
${bakPath}/${project.name}-${date}/${variant.flavorName}"
):
bakPath
//复制apk文件和重命名
fromvariant.outputs.outputFile
intodestPath
rename{StringfileName->
fileName.replace("
${fileNamePrefix}.apk"
${newFileNamePrefix}_tinker.apk"
//复制和重命名mapping文件
from"
${buildDir}/outputs/mapping/${variant.dirName}/mapping.txt"
${newFileNamePrefix}_mapping.txt"
//复制和重命名R文件
${buildDir}/intermediates/symbols/${variant.dirName}/R.txt"
${newFileNamePrefix}_R.txt"
有了上面这些基本的配置,基本上tinker的引入就算完成了。
这里要说一下引入multidex的目的不仅是解决65536的限制,还有就是因为tinker的修复原理是de
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Android 更新 框架 Tinker 探索