Tinker Demo运行问题

运行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获得版本号失败导致
解决方法:

  1. gradle.properties中添加TINKER_ID=1(这个数字可以随便写,或者就是versionCode都行)
  2. gitSha()方法直接返回数字(数值同上)

如何生成patch补丁

  1. 运行项目,安装apk到手机中,这里生成的apk即oldApk,在app/build/bakApk下面
  2. 生成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)

  1. gradle运行tinkerPathDebug命令
  2. apk/build/outputs/tinkerPatch/debug中生成的patch_signed_7zip.apkpush到手机中,运行即可

你可能感兴趣的:(Tinker Demo运行问题)