集成地址:https://blog.csdn.net/Blog_Sun/article/details/88035496
thinker 后台地址: http://www.tinkerpatch.com
Android studio thinkerpatch.gradle 配置
import java.util.regex.Matcher import java.util.regex.Pattern apply plugin: 'tinkerpatch-support' /** * TODO: 请按自己的需求修改为适应自己工程的参数dc03177f348e3619 */ //基包路径 def bakPath = file("${buildDir}/bakApk/") //基包文件夹名(打补丁包的时候,需要修改) def baseInfo = "app-1.0.0-0505-10-56-33" //版本名称 def variantName = "debug" /** * 对于插件各参数的详细解析请参考 * http://tinkerpatch.com/Docs/SDK */ tinkerpatchSupport { /** 可以在debug的时候关闭 tinkerPatch, isRelease() 可以判断BuildType是否为Release **/ tinkerEnable = true reflectApplication = true /** * 是否开启加固模式,只能在APK将要进行加固时使用,否则会patch失败。 * 如果只在某个渠道使用了加固,可使用多flavors配置 **/ protectedApp = false /** * 实验功能 * 补丁是否支持新增 Activity (新增Activity的exported属性必须为false) **/ supportComponent = true autoBackupApkPath = "${bakPath}" appKey = "自己的appkey" /** 注意: 若发布新的全量包, appVersion一定要更新 **/ 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" /** * (可选)重命名备份文件的格式化字符串,默认为'${appName}-${variantName}' * * Available vars: * 1. projectName * 2. appName * 3. packageName * 4. buildType * 5. versionName * 6. versionCode * 7. buildTime * 8. fileSHA1 * 9. flavorName * 10. variantName * * default value: '${appName}-${variantName}' * Note: plz use single-quotation wrapping this format string */ backupFileNameFormat = '${appName}-${variantName}' /** * 若有编译多flavors需求, 可以参照: https://github.com/TinkerPatch/tinkerpatch-flavors-sample * 注意: 除非你不同的flavor代码是不一样的,不然建议采用zip comment或者文件方式生成渠道信息(相关工具:walle 或者 packer-ng) **/ } /** * 用于用户在代码中判断tinkerPatch是否被使能 */ android { defaultConfig { buildConfigField "boolean", "TINKER_ENABLE", "${tinkerpatchSupport.tinkerEnable}" } } /** * 一般来说,我们无需对下面的参数做任何的修改 * 对于各参数的详细介绍请参考: * https://github.com/Tencent/tinker/wiki/Tinker-%E6%8E%A5%E5%85%A5%E6%8C%87%E5%8D%97 */ tinkerPatch { ignoreWarning = false useSign = true 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 } } /** * 如果只想在Release中打开tinker,可以把tinkerEnable赋值为这个函数的return * @return 是否为release */ def isRelease() { Gradle gradle = getGradle() String tskReqStr = gradle.getStartParameter().getTaskRequests().toString() Pattern pattern; if (tskReqStr.contains("assemble")) { println tskReqStr pattern = Pattern.compile("assemble(\\w*)(Release|Debug)") } else { pattern = Pattern.compile("generate(\\w*)(Release|Debug)") } Matcher matcher = pattern.matcher(tskReqStr) if (matcher.find()) { String task = matcher.group(0).toLowerCase() println("[BuildType] Current task: " + task) return task.contains("release") } else { println "[BuildType] NO MATCH FOUND" return true; } }