tinker的接入和管理
##SDK接入 *第一步 添加 gradle 插件依赖
buildscript {
repositories {
jcenter()
}
dependencies {
// TinkerPatch 插件
classpath "com.tinkerpatch.sdk:tinkerpatch-gradle-plugin:{tinker-version}"
}
}
*第二步 集成 TinkerPatch SDK
dependencies {
// 若使用annotation需要单独引用,对于tinker的其他库都无需再引用
provided("com.tencent.tinker:tinker-android-anno:1.7.7")
compile("com.tinkerpatch.sdk:tinkerpatch-android-sdk:{tinker-version}")
}
apply from: 'tinkerpatch.gradle'
*第三步 配置 tinkerpatchSupport 参数
打开引入的 tinkerpatch.gradle 文件,它的具体参数如下:
tinkerpatchSupport {
tinkerpatchSupport {
/** 可以在debug的时候关闭 tinkerPatch **/
tinkerEnable = true
reflectApplication = true
autoBackupApkPath = "${bakPath}"
/** 在tinkerpatch.com得到的appKey **/
appKey = "yourAppKey"
appVersion = "1.0.0"
def pathPrefix = "${bakPath}/${baseInfo}/${variantName}/"
def name = "${project.name}-${variantName}"
baseApkFile = "${pathPrefix}/${name}.apk"
baseProguardMappingFile = "${pathPrefix}/${name}-mapping.txt"
baseResourceRFile = "${pathPrefix}/${name}-R.txt"
}
public class MyApplication extends Application{
private ApplicationLike tinkerApplicationLike;
@Override
public void onCreate() {
super.onCreate();
//我们可以从这里获得Tinker加载过程的信息
//要使用tinker补丁的时候取消注释
//设置app builder中的buildWithTinker=true;把原始apk复制到对应文件夹下,这里的路径为${bakPath}/${appName}/,
//再生成补丁
tinkerApplicationLike = TinkerPatchApplicationLike.getTinkerPatchApplicationLike();
/*
//开始检查是否有补丁,这里配置的是每隔访问3小时服务器是否有更新。
TinkerPatch.init(tinkerApplicationLike)
.reflectPatchLibrary()
.setPatchRollbackOnScreenOff(true)
.setPatchRestartOnSrceenOff(true);
TinkerPatch.with().fetchPatchUpdate(false);
//锁屏时自动重启应用进行更新
TinkerPatch.with().setPatchRestartOnSrceenOff(true);
*/
}
第五步 使用步骤
- 运行 assembleRelease task 构建基准包,即将要发布的版本;
- 通过 autoBackupApkPath 保存编译的产物 apk/mapping.txt/R.txt 文件;
- 若想发布补丁包, 只需将步骤2保存下来的文件分别填到 baseApkFile/baseProguardMappingFile/baseResourceRFile 参数中;
- 运行 tinkerPatchRelease task 构建补丁包,补丁包将位于 build/outputs/tinkerPatch 中;(每次生成布丁都是跟线上的apk进行比较)