运行Tinker Demo问题记录
找不到tinker id
app的build.gradle
中
def getTinkerIdValue() {
return hasProperty("TINKER_ID") ? TINKER_ID : gitSha()
}
def gitSha() {
try {
String gitRev = 'git rev-parse --short HEAD'.execute(null, project.rootDir).text.trim()
if (gitRev == null) {
throw new GradleException("can't get git rev, you should add git to system path or just input test value, such as 'testTinkerId'")
}
return gitRev
} catch (Exception e) {
throw new GradleException("can't get git rev, you should add git to system path or just input test value, such as 'testTinkerId'")
}
}
因为没有TINKER_ID
属性,而gitSha通过git获得版本号失败导致
解决方法:
-
gradle.properties
中添加TINKER_ID=1
(这个数字可以随便写,或者就是versionCode都行) -
gitSha()
方法直接返回数字(数值同上)
如何生成patch补丁
- 运行项目,安装apk到手机中,这里生成的apk即oldApk,在
app/build/bakApk
下面 - 生成patch需要修改app的
build.gralde
文件
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-0809-18-10-57.apk"
//proguard mapping file to build patch apk
tinkerApplyMappingPath = "${bakPath}/app-debug-0809-18-10-57-mapping.txt"
//resource R.txt to build patch apk, must input if there is resource changed
tinkerApplyResourcePath = "${bakPath}/app-debug-0809-18-10-57-R.txt"
//only use for build all flavor, if not, just ignore this field
tinkerBuildFlavorDirectory = "${bakPath}/app-0809-18-10-57"
}
这里要将apk的名字修改成上一步bakApk中对应文件名(每次运行都会生成新的apk,这里要对应手机上安装的那个apk)
- gradle运行
tinkerPathDebug
命令 - 将
apk/build/outputs/tinkerPatch/debug
中生成的patch_signed_7zip.apk
push到手机中,运行即可