1.从https://github.com/Tencent/tinker下载代码,然后用android studio打开tinker-sample-android
2.在module的build.gradle修改gitSha
def gitSha() {
return 32323
}
如果不修改会报错,这个方法,也就是获取git最近一次commit的版本号,所以要是你的当前Project没有配置git,或者当前的Project还没有commit过,
或者git没有加入到环境变量中,会获取不到该值。知道了原理,那解决方式就自己想了,我这里就直接写死,上面这个方法直接返回固定字符串。
3.在build.gradle这里配置旧的apk和新apk:
def bakPath = file("${buildDir}/bakApk/")这个path可以改的:
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-debug-0519-10-42-25.apk" //proguard mapping file to build patch apk tinkerApplyMappingPath = "${bakPath}/app-debug-0519-10-47-45-mapping.txt" //resource R.txt to build patch apk, must input if there is resource changed tinkerApplyResourcePath = "${bakPath}/app-debug-0519-10-47-45-R.txt" //only use for build all flavor, if not, just ignore this field tinkerBuildFlavorDirectory = "${bakPath}/app-1018-17-32-47" }
目前这个path是android studio上的
4.生成patch_signed_7zip.apk:
修改代码或是布局文件后,点击android studio右侧gradle按钮:
双击tinkerPatchDebug,然后会在
生成这个文件
5.然后apply path是:
TinkerInstaller.onReceiveUpgradePatch(getApplicationContext(), Environment.getExternalStorageDirectory().getAbsolutePath() + "/patch_signed_7zip.apk");
把patch_signed_7zip.apk放在这个目录下,然后执行上一句,就可以apply path了