**
Tinker热修复从 0 —1 完整集成
**
因为给新手看所以讲的非常细,文章比较长,希望能帮助大家。
废话不多说,咱们直接来干货。
**
第一步:
**
在项目的Build.gradle中添加
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath ‘com.android.tools.build:gradle:3.4.2’// NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files // tinkersupport插件, 其中lastest.release指拉取最新版本,也可以指定明确版本号,例如1.0.4 classpath "com.tencent.bugly:tinker-support:1.2.0" } }
修改gradle-wrapper.properties 为:
distributionUrl=https://services.gradle.org/distributions/gradle-5.5-all.zip
第二步:
配置App目录下的Build.Gradle
在android 上 添加:
// 依赖插件脚本 apply from: ‘tinker-support.gradle’
在defaultConfig中 添加:
ndk {
//设置支持的SO库架构
abiFilters ‘armeabi’ //, ‘x86’, ‘armeabi-v7a’, ‘x86_64’, ‘arm64-v8a’
}
添加依赖:
implementation “com.android.support:multidex:1.0.1” // 多dex配置
//注释掉原有bugly的仓库
//compile ‘com.tencent.bugly:crashreport:latest.release’//其中latest.release指代最新版本号,也可以指定明确的版本号,例如1.3.4
implementation ‘com.tencent.bugly:crashreport_upgrade:1.3.6’
// 指定tinker依赖版本(注:应用升级1.3.5版本起,不再内置tinker)
implementation ‘com.tencent.tinker:tinker-android-lib:1.9.9’
implementation ‘com.tencent.bugly:nativecrashreport:latest.release’
//其中latest.release指代最新版本号,也可以指定明确的版本号,例如2.2.0
implementation “com.android.support:multidex:1.0.1”
在app目录下创建一个文件 名字叫:tinker-support.gradle
在文件中添加代码:
apply plugin: ‘com.tencent.bugly.tinker-support’
def bakPath = file("${buildDir}/bakApk/")
/** * 此处填写每次构建生成的基准包目录 */ def baseApkDir = “app-0208-15-10-00”
/** * 对于插件各参数的详细解析请参考 */ tinkerSupport {
// 开启tinker-support插件,默认值true enable = true // 指定归档目录,默认值当前module的子目录tinker autoBackupApkDir = "${bakPath}" // 是否启用覆盖tinkerPatch配置功能,默认值false // 开启后tinkerPatch配置不生效,即无需添加tinkerPatch overrideTinkerPatchConfiguration = true // 编译补丁包时,必需指定基线版本的apk,默认值为空 // 如果为空,则表示不是进行补丁包的编译 // @{link tinkerPatch.oldApk } baseApk = "${bakPath}/${baseApkDir}/app-release.apk" // 对应tinker插件applyMapping baseApkProguardMapping = "${bakPath}/${baseApkDir}/app-release-mapping.txt" // 对应tinker插件applyResourceMapping baseApkResourceMapping = "${bakPath}/${baseApkDir}/app-release-R.txt" // 构建基准包和补丁包都要指定不同的tinkerId,并且必须保证唯一性 tinkerId = "base-1.0.1" // 构建多渠道补丁时使用 // buildAllFlavorsDir = "${bakPath}/${baseApkDir}" // 是否启用加固模式,默认为false.(tinker