android開發中使用tinker對app進行熱修復教程。
項目裡包含瞭lib的源碼和sample,下下來,然後打開tinker-sample-android:
修改mainActivity中textview:
通過gradle生成release版的apk:
在app/build/bakApk目錄下會生成apk,混淆映射文件和資源文件:
通過adb運行:
adb install -r -d F:\AndroidProgram\Demo\tinker\tinker-sample-android\app\build\bakApk\app-release-1025-10-46-35.apk
下面修改app的build.gradle文件:
ext { //for some reason, you may want to ignore tinkerBuild, such as instant run debug build? tinkerEnabled = true //for normal build //old apk file to build patch apk tinkerOldApkPath = "${bakPath}/app-release-1025-10-46-35.apk" //proguard mapping file to build patch apk tinkerApplyMappingPath = "${bakPath}/app-release-1025-10-46-35-mapping.txt" //resource R.txt to build patch apk, must input if there is resource changed tinkerApplyResourcePath = "${bakPath}/app-release-1025-10-46-35-R.txt" //only use for build all flavor, if not, just ignore this field tinkerBuildFlavorDirectory = "${bakPath}/app-1018-17-32-47" }
將打包生成的老apk的三個文件對應填入tinkerOldApkPath、tinkerApplyMappingPath、tinkerApplyResourcePath,然後我們準備新版本apk,修改代碼,也是改mainactivity中的textview:
不要clean,不然android studio會刪除之前打包好的apk,然後用gradle裡的tinker打包:
會生成新的release版apk:
tinker對比新舊apk的差異生成一個補丁文件patch_signed_7zip.apk:
把這個補丁文件push到手機內存根目錄:
adb push F:\AndroidProgram\Demo\tinker\tinker-sample-android\app\build\outputs\tinkerPatch\release\patch_signed_7zip.apk /sdcard/
回到運行的app中,點擊LOAD PATCH:
然後點擊KILL SELF,再次進入app,改動就生效瞭,同時刪除瞭存儲卡上的補丁文件:
demo裡還提供瞭去掉補丁功能,點擊CLEAN PATCH,再KILL SELF,重啟app就是舊的版本。