Skip to content

Commit fa07f02

Browse files
committed
集成 tinker 热更新
1 parent 55c8864 commit fa07f02

File tree

7 files changed

+141
-11
lines changed

7 files changed

+141
-11
lines changed

Diff for: app/build.gradle

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ apply plugin: 'kotlin-android'
33
apply plugin: 'kotlin-android-extensions'
44
// apply plugin: 'kotlin-kapt'
55

6+
// 依赖 tinker 插件脚本
7+
apply from: 'tinker-support.gradle'
8+
69
android {
710
compileSdkVersion rootProject.ext.android.compileSdkVersion
811

Diff for: app/proguard-rules.pro

+3
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,9 @@
241241
-dontwarn com.tencent.bugly.**
242242
-keep public class com.tencent.bugly.**{*;}
243243
-keep class android.support.**{*;}
244+
# tinker混淆规则
245+
-dontwarn com.tencent.tinker.**
246+
-keep class com.tencent.tinker.** { *; }
244247

245248
################ autolayout ###############
246249
-keep class com.zhy.autolayout.** { *; }

Diff for: app/src/main/java/com/cxz/wanandroid/app/App.kt

+17-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
package com.cxz.wanandroid.app
22

3-
43
import android.app.Activity
54
import android.app.Application
65
import android.content.Context
76
import android.os.Bundle
87
import android.os.Environment
9-
import android.support.multidex.MultiDexApplication
8+
import android.support.multidex.MultiDex
109
import android.support.v7.app.AppCompatDelegate
1110
import android.util.Log
1211
import com.cxz.wanandroid.BuildConfig
@@ -33,7 +32,7 @@ import kotlin.properties.Delegates
3332
/**
3433
* Created by chenxz on 2018/4/21.
3534
*/
36-
class App : MultiDexApplication() {
35+
class App : Application() {
3736

3837
private var refWatcher: RefWatcher? = null
3938

@@ -84,7 +83,8 @@ class App : MultiDexApplication() {
8483
val strategy = CrashReport.UserStrategy(applicationContext)
8584
strategy.isUploadProcess = false || processName == packageName
8685
// 设置sd卡的Download为更新资源保存目录;
87-
Beta.storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)
86+
Beta.storageDir =
87+
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)
8888

8989
Beta.upgradeStateListener = object : UpgradeStateListener {
9090
override fun onDownloadCompleted(isManual: Boolean) {
@@ -122,6 +122,14 @@ class App : MultiDexApplication() {
122122
Bugly.init(applicationContext, Constant.BUGLY_ID, BuildConfig.DEBUG, strategy)
123123
}
124124

125+
override fun attachBaseContext(base: Context?) {
126+
super.attachBaseContext(base)
127+
MultiDex.install(base)
128+
129+
// 安装 Tinker
130+
Beta.installTinker()
131+
}
132+
125133
/**
126134
* 初始化 LitePal
127135
*/
@@ -176,11 +184,11 @@ class App : MultiDexApplication() {
176184
*/
177185
private fun initConfig() {
178186
val formatStrategy = PrettyFormatStrategy.newBuilder()
179-
.showThreadInfo(false) // 隐藏线程信息 默认:显示
180-
.methodCount(0) // 决定打印多少行(每一行代表一个方法)默认:2
181-
.methodOffset(7) // (Optional) Hides internal method calls up to offset. Default 5
182-
.tag("hao_zz") // (Optional) Global tag for every log. Default PRETTY_LOGGER
183-
.build()
187+
.showThreadInfo(false) // 隐藏线程信息 默认:显示
188+
.methodCount(0) // 决定打印多少行(每一行代表一个方法)默认:2
189+
.methodOffset(7) // (Optional) Hides internal method calls up to offset. Default 5
190+
.tag("hao_zz") // (Optional) Global tag for every log. Default PRETTY_LOGGER
191+
.build()
184192
Logger.addLogAdapter(object : AndroidLogAdapter(formatStrategy) {
185193
override fun isLoggable(priority: Int, tag: String?): Boolean {
186194
return BuildConfig.DEBUG

Diff for: app/src/main/res/xml/provider_paths.xml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<paths>
3+
<!-- /storage/emulated/0/Download/${applicationId}/.beta/apk-->
4+
<external-path
5+
name="beta_external_path"
6+
path="Download/" />
7+
<!--/storage/emulated/0/Android/data/${applicationId}/files/apk/-->
8+
<external-path
9+
name="beta_external_files_path"
10+
path="Android/data/" />
11+
</paths>

Diff for: app/tinker-support.gradle

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/**
2+
* Bugly Android热更新详解:
3+
* https://bugly.qq.com/docs/user-guide/instruction-manual-android-hotfix-demo/
4+
*/
5+
6+
apply plugin: 'com.tencent.bugly.tinker-support'
7+
8+
def bakPath = file("${buildDir}/bakApk/")
9+
10+
/**
11+
* 此处填写每次构建生成的基准包目录
12+
*/
13+
def baseApkDir = "app-1026-22-10-05"
14+
15+
/**
16+
* 构建基准包和补丁包都要指定不同的tinkerId,并且必须保证唯一性
17+
*/
18+
def tinkerIdV = "patch-1.1.3"
19+
20+
/**
21+
* 对于插件各参数的详细解析请参考
22+
*/
23+
tinkerSupport {
24+
25+
// 开启tinker-support插件,默认值true
26+
enable = true
27+
28+
// 指定归档目录,默认值当前module的子目录tinker
29+
autoBackupApkDir = "${bakPath}"
30+
31+
// 是否启用覆盖tinkerPatch配置功能,默认值false
32+
// 开启后tinkerPatch配置不生效,即无需添加tinkerPatch
33+
overrideTinkerPatchConfiguration = true
34+
35+
// 编译补丁包时,必需指定基线版本的apk,默认值为空
36+
// 如果为空,则表示不是进行补丁包的编译
37+
// @{link tinkerPatch.oldApk }
38+
baseApk = "${bakPath}/${baseApkDir}/WanAndroid-release.apk"
39+
40+
// 对应tinker插件applyMapping
41+
baseApkProguardMapping = "${bakPath}/${baseApkDir}/app-release-mapping.txt"
42+
43+
// 对应tinker插件applyResourceMapping
44+
baseApkResourceMapping = "${bakPath}/${baseApkDir}/app-release-R.txt"
45+
46+
// 构建基准包和补丁包都要指定不同的tinkerId,并且必须保证唯一性
47+
tinkerId = tinkerIdV
48+
49+
// 构建多渠道补丁时使用
50+
// buildAllFlavorsDir = "${bakPath}/${baseApkDir}"
51+
52+
// 是否启用加固模式,默认为false.(tinker-spport 1.0.7起支持)
53+
// isProtectedApp = true
54+
55+
// 是否开启反射Application模式
56+
enableProxyApplication = true
57+
58+
// 是否支持新增非export的Activity(注意:设置为true才能修改AndroidManifest文件)
59+
supportHotplugComponent = true
60+
61+
}
62+
63+
/**
64+
* 一般来说,我们无需对下面的参数做任何的修改
65+
* 对于各参数的详细介绍请参考:
66+
* https://github.com/Tencent/tinker/wiki/Tinker-%E6%8E%A5%E5%85%A5%E6%8C%87%E5%8D%97
67+
*/
68+
tinkerPatch {
69+
//oldApk ="${bakPath}/${appName}/app-release.apk"
70+
ignoreWarning = false
71+
useSign = true
72+
dex {
73+
dexMode = "jar"
74+
pattern = ["classes*.dex"]
75+
loader = []
76+
}
77+
lib {
78+
pattern = ["lib/*/*.so"]
79+
}
80+
81+
res {
82+
pattern = ["res/*", "r/*", "assets/*", "resources.arsc", "AndroidManifest.xml"]
83+
ignoreChange = []
84+
largeModSize = 100
85+
}
86+
87+
packageConfig {
88+
}
89+
sevenZip {
90+
zipArtifact = "com.tencent.mm:SevenZip:1.1.10"
91+
// path = "/usr/local/bin/7za"
92+
}
93+
buildConfig {
94+
keepDexApply = false
95+
//tinkerId = "1.0.1-base"
96+
//applyMapping = "${bakPath}/${appName}/app-release-mapping.txt" // 可选,设置mapping文件,建议保持旧apk的proguard混淆方式
97+
//applyResourceMapping = "${bakPath}/${appName}/app-release-R.txt" // 可选,设置R.txt文件,通过旧apk文件保持ResId的分配
98+
}
99+
}

Diff for: build.gradle

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ buildscript {
1313
classpath 'com.android.tools.build:gradle:3.5.1'
1414
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1515

16+
// tinkersupport插件, 其中lastest.release指拉取最新版本,也可以指定明确版本号,例如1.0.4
17+
classpath "com.tencent.bugly:tinker-support:1.2.0"
18+
1619
// NOTE: Do not place your application dependencies here; they belong
1720
// in the individual module build.gradle files
1821
}

Diff for: config.gradle

+5-2
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,11 @@ ext {
6666
//"vertical-tablayout": 'q.rorbin:VerticalTabLayout:1.2.5',
6767
"flow-layout" : 'com.hyman:flowlayout-lib:1.1.2',
6868
"eventbus" : 'org.greenrobot:eventbus:3.1.1',
69-
//"bugly" : 'com.tencent.bugly:crashreport:2.6.6.1',
70-
"bugly-crash-up" : 'com.tencent.bugly:crashreport_upgrade:1.3.5',
69+
//"bugly" : 'com.tencent.bugly:crashreport:3.1.0',
70+
"bugly-crash-up" : 'com.tencent.bugly:crashreport_upgrade:1.4.2',
71+
// 指定tinker依赖版本(注:应用升级1.3.5版本起,不再内置tinker)
72+
'tinker' : 'com.tencent.tinker:tinker-android-lib:1.9.14.3',
73+
//'nativecrashreport' : 'com.tencent.bugly:nativecrashreport:3.7.1',//latest.release
7174
"swipeback" : 'com.cxz:swipeback:1.0.1',
7275
"material-dialogs" : 'com.afollestad.material-dialogs:commons:0.9.4.4',
7376
"logger" : 'com.orhanobut:logger:2.1.1',

0 commit comments

Comments
 (0)