环境:
gradle_version:3.6.1 5.6.4
minSdkVersion 21
targetSdkVersion 30
compileSdkVersion 30
buildToolsVersion "30.0.2"
项目根目录build.gradle
dependencies { classpath "com.tencent.bugly:tinker-support:1.2.3" }
没错就是1.2.3 最新文档 1.2.1 我试出来的 gradle_version:3.6.1 在1.2.1一直报错
tinker-support.gradle
在根目录创建tinker-support.gradle文件,内容如下
apply plugin: 'com.tencent.bugly.tinker-support'def
bakPath = file("${buildDir}/bakApk/")
//app版本
def versionName = appVersionName
/** * todo 补丁包需要对应的基准APK-此处填写每次构建生成的基准包目录 */
def baseApkDir = "app-0720-10-12-09"
//是否打补丁包
def isPatch = false
//补丁版本def patchVersion = "0.0.1"
//一般正式包不需要改
def BUILD_TYPE = "release"
/**打补丁包必填 基准APK路径*/
def mBasePath = "${bakPath}/${baseApkDir}"
def mBaseApk = "${mBasePath}/app-${BUILD_TYPE}.apk"
if (!isPatch) { mBaseApk = null}
// 用于生成基准包(不用修改)
def mBaseTinkerId = "base-" + versionName
// 用于生成补丁包(每次生成补丁包都要修改一次,最好是 patch-${versionName}.x.x)
def myPatchTinkerId = "patch-" + versionName + "-${patchVersion}"
/**TODO TinkerId 唯一标识区分 [补丁包\基准包] */
def mTinkerId = mBaseTinkerIdif (isPatch) { mTinkerId = myPatchTinkerId} else { mTinkerId = mBaseTinkerId}
/** * 对于插件各参数的详细解析请参考,如果没有特殊需求下面的参数都可以不用更改;如果apk需要加固等可以参考具体描述设置参数 *
/tinkerSupport {
// 开启tinker-support插件,默认值true
enable = true
// 指定归档目录,默认值当前module的子目录tinker
autoBackupApkDir = "${bakPath}"
//建议设置true,用户就不用再自己管理tinkerId的命名,插件会为每一次构建的base包自动生成唯一的tinkerId,默认命名规则是versionname.versioncode_时间戳 //具体参考https://github.com/BuglyDevTeam/Bugly-Android-Demo/wiki/Tinker-ID%E8%AF%A5%E6%80%8E%E4%B9%88%E8%AE%BE%E7%BD%AE
autoGenerateTinkerId = true
// 是否启用覆盖tinkerPatch配置功能,默认值false
// 开启后tinkerPatch配置不生效,即无需添加tinkerPatch
overrideTinkerPatchConfiguration = true
// 编译补丁包时,必需指定基线版本的apk,默认值为空
// 如果为空,则表示不是进行补丁包的编译
// @{link tinkerPatch.oldApk }
baseApk = mBaseApk
// 对应tinker插件applyMapping
baseApkProguardMapping = "${mBasePath}/app-${BUILD_TYPE}-mapping.txt"
// 对应tinker插件applyResourceMapping
baseApkResourceMapping = "${mBasePath}/app-${BUILD_TYPE}-R.txt"
//tinkerId必须保证唯一性,如果两个base包的tinkerid是一样的,并且都联网激活了,那么后续补丁上传到后台的时候会出现匹配错误 //构建基准包和补丁包都要指定不同的tinkerId,并且必须保证唯一性{if autoGenerateTinkerId=true ,no need set here}
//在运行过程中,我们需要验证基准apk包的tinkerId是否等于补丁包的tinkerId。这个是决定补丁包能运行在哪些基准包上面,一般来说我们可以使用git版本号、versionName等等。
tinkerId = mTinkerId
/**构建多渠道时-使用*/
//buildAllFlavorsDir = "${mBasePath}"
// 是否开启加固模式,默认为false
isProtectedApp = true
enableProxyApplication = false
supportHotplugComponent = true
}
/** * 一般来说,我们无需对下面的参数做任何的修改
* 对于各参数的详细介绍请参考:
* https://github.com/Tencent/tinker/wiki/Tinker-%E6%8E%A5%E5%85%A5%E6%8C%87%E5%8D%97 */
tinkerPatch { //如果项目的minSdkVersion>=21,升级到1.9.14并开启allowLoaderInAnyDex和removeLoaderForAllDex
allowLoaderInAnyDex = true
removeLoaderForAllDex = true
// oldApk ="${bakPath}/${appName}/app-debug.apk"
ignoreWarning = false
useSign = false
dex { dexMode = "jar" pattern = ["classes*.dex"] loader = [] }
lib { pattern = ["lib/*/*.so"] }
res { pattern = ["res/*", "r/*", "assets/*", "resources.arsc", "AndroidManifest.xml"] ignoreChange = [] largeModSize = 100 }
packageConfig { }
sevenZip { zipArtifact = "com.tencent.mm:SevenZip:1.1.10"// path = "/usr/local/bin/7za" }
buildConfig { keepDexApply = false }
}
注意在minSdkVersion >21时 添加
allowLoaderInAnyDex = true
removeLoaderForAllDex = true
APP 的 gradle
// 依赖插件脚本
apply from: 'tinker-support.gradle'
dependencies {
implementation 'com.tencent.bugly:crashreport_upgrade:1.5.23
implementation 'com.tencent.tinker:tinker-android-lib:1.9.14.17'
implementation 'com.tencent.bugly:nativecrashreport:latest.release' }
附带地址: https://github.com/Tencent/tinker/releases?after=v1.9.14.8
其他配置看文档就行