運(yùn)行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'")
}
}
因?yàn)闆]有TINKER_ID
屬性累提,而gitSha通過git獲得版本號失敗導(dǎo)致
解決方法:
-
gradle.properties
中添加TINKER_ID=1
(這個數(shù)字可以隨便寫挖息,或者就是versionCode都行) -
gitSha()
方法直接返回?cái)?shù)字(數(shù)值同上)
如何生成patch補(bǔ)丁
- 運(yùn)行項(xiàng)目,安裝apk到手機(jī)中,這里生成的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中對應(yīng)文件名(每次運(yùn)行都會生成新的apk耗帕,這里要對應(yīng)手機(jī)上安裝的那個apk)
- gradle運(yùn)行
tinkerPathDebug
命令 - 將
apk/build/outputs/tinkerPatch/debug
中生成的patch_signed_7zip.apk
push到手機(jī)中,運(yùn)行即可