一、我的项目配置是这样的:
1、app的gradle配置:
dependencies {
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
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:latest.release'
// 指定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
}
2、项目级gradle配置:
buildscript {
repositories {
maven {
url 'http://maven.aliyun.com/nexus/content/groups/public/'
}
maven { url "https://jitpack.io" }
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:3.4.1"
// tinkersupport插件, 其中lastest.release指拉取最新版本,也可以指定明确版本号,例如1.0.4
classpath "com.tencent.bugly:tinker-support:latest.release"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
maven {
url 'http://maven.aliyun.com/nexus/content/groups/public/'
}
maven { url "https://jitpack.io" }
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
3、Application类配置:
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
// 这里实现SDK初始化,appId替换成你的在Bugly平台申请的appId
// 调试时,将第三个参数改为true
Bugly.init(this, "ea8d983059", false);
}
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
// you must install multiDex whatever tinker is installed!
MultiDex.install(base);
// 安装tinker
Beta.installTinker();
}
}
4、tinker-support.gradle文件内容:
apply plugin: 'com.tencent.bugly.tinker-support'
def bakPath = file("${buildDir}/bakApk/")
/**
* 此处填写每次构建生成的基准包目录
*/
def baseApkDir = "app-0220-15-11-42"
/**
* 对于插件各参数的详细解析请参考
*/
tinkerSupport {
// 开启tinker-support插件,默认值true
enable = true
// 自动生成tinkerId, 你无须关注tinkerId,默认为false
autoGenerateTinkerId = true
// 指定归档目录,默认值当前module的子目录tinker
autoBackupApkDir = "${bakPath}"
// 是否启用覆盖tinkerPatch配置功能,默认值false
// 开启后tinkerPatch配置不生效,即无需添加tinkerPatch
overrideTinkerPatchConfiguration = true
// 编译补丁包时,必需指定基线版本的apk,默认值为空
// 如果为空,则表示不是进行补丁包的编译
// @{link tinkerPatch.oldApk }
baseApk = "${bakPath}/${baseApkDir}/TinkerDemo.apk"
// baseApk = "${bakPath}/${baseApkDir}/app-debug.apk"
// 对应tinker插件applyMapping
baseApkProguardMapping = "${bakPath}/${baseApkDir}/app-release-mapping.txt"
// baseApkProguardMapping = "${bakPath}/${baseApkDir}/app-debug-mapping.txt"
// 对应tinker插件applyResourceMapping
baseApkResourceMapping = "${bakPath}/${baseApkDir}/app-release-R.txt"
// baseApkResourceMapping = "${bakPath}/${baseApkDir}/app-debug-R.txt"
// 构建基准包跟补丁包都要修改tinkerId,主要用于区分
tinkerId = "tinker-${buildTime()}"
// tinkerId = "4"
// 打多渠道补丁时指定目录
// buildAllFlavorsDir = "${bakPath}/${baseApkDir}"
// 是否使用加固模式,默认为false
// isProtectedApp = true
// 是否采用反射Application的方式集成,无须改造Application
enableProxyApplication = true
// 支持新增Activity
supportHotplugComponent = true
}
/**
* 一般来说,我们无需对下面的参数做任何的修改
* 对于各参数的详细介绍请参考:
* https://github.com/Tencent/tinker/wiki/Tinker-%E6%8E%A5%E5%85%A5%E6%8C%87%E5%8D%97
*/
tinkerPatch {
tinkerEnable = true
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
// tinkerId = "base-2.0.1"
}
}
def buildTime(){
return new Date().format("MMdd-HH-mm-ss", TimeZone.getTimeZone("GMT+8"))
}
二、结果:
1、生成基础包可以正常生成,且补丁包也可以正常生成。
生成补丁包的log.txt:
-----------------------Tinker patch begin-----------------------
configuration:
oldApk:/Users/muyang/code-demo/TinkerDemo/app/build/bakApk/app-0220-15-11-42/TinkerDemo.apk
newApk:/Users/muyang/code-demo/TinkerDemo/app/build/outputs/apk/release/TinkerDemo.apk
outputFolder:/Users/muyang/code-demo/TinkerDemo/app/build/outputs/apk/tinkerPatch/release
isIgnoreWarning:false
isAllowLoaderClassInAnyDex:false
isRemoveLoaderForAllDex:false
isProtectedApp:false
7-ZipPath:/Users/muyang/.gradle/caches/modules-2/files-2.1/com.tencent.mm/SevenZip/1.1.10/cc390e6c704b74496d9ba0e9b46d2cf8a2a96b84/SevenZip-1.1.10-osx-x86_64.exe
useSignAPk:true
package meta fields:
dex configs:
dexMode: jar
dexPattern:assets/secondary-dex-.\.jar
dexPattern:classes.*\.dex
dex loader:com.tencent.tinker.loader.*
dex loader:com.tencent.bugly.beta.tinker.TinkerPatchReflectApplication
lib configs:
libPattern:lib/.*/.*\.so
resource configs:
resPattern:r/.*
resPattern:resources\.arsc
resPattern:assets/.*
resPattern:res/.*
resPattern:AndroidManifest\.xml
resIgnore change:assets/.*_meta\.txt
largeModSize:100kb
useApplyResource:true
ArkHot: arkHot / patch.apk
config: arkHot patch.apkassets/arkHot_meta.txt
Analyze old and new apk files1:
old apk1131: TinkerDemo.apk, size=2737203, md5=2784554e97c9f1df7b27f5789c033841
new apk: TinkerDemo.apk, size=2737415, md5=15a419abff5bd51529c2105a643d466c
Manifest was changed, while there's no any new components added. Make sure if such changes were all you expected.
UnZipping apk to /Users/muyang/code-demo/TinkerDemo/app/build/outputs/apk/tinkerPatch/release/TinkerDemo-old
UnZipping apk to /Users/muyang/code-demo/TinkerDemo/app/build/outputs/apk/tinkerPatch/release/TinkerDemo-new
found modify resource: AndroidManifest.xml, but it is AndroidManifest.xml, just ignore!
Check for loader classes in dex: classes.dex
Gen classes.dex patch file:/Users/muyang/code-demo/TinkerDemo/app/build/outputs/apk/tinkerPatch/release/tinker_result/classes.dex, size:777, md5:469a7535ea241b8fe99e8f47b2029170
Verifying if patched new dex is logically the same as original new dex: TinkerDemo-new/classes.dex ...
Gen classes.dex for dalvik full dex file:/Users/muyang/code-demo/TinkerDemo/app/build/outputs/apk/tinkerPatch/release/tempPatchedDexes/classes.dex, size:3976712, md5:a2bbe2cfe06420eaea799bdd0428b9e8
DexDecoder:write meta file data: classes.dex,,a2bbe2cfe06420eaea799bdd0428b9e8,a2bbe2cfe06420eaea799bdd0428b9e8,469a7535ea241b8fe99e8f47b2029170,1222112166,2264125920,jar
Add test install result dex: /Users/muyang/code-demo/TinkerDemo/app/build/outputs/apk/tinkerPatch/release/tinker_result/test.dex, size:584
DexDecoder:write test dex meta file data: test.dex,,56900442eb5b7e1de45449d0685e6e00,56900442eb5b7e1de45449d0685e6e00,0,0,0,jar
Generate unsigned apk: patch_unsigned.apk
Signing apk: patch_signed.apk
Signing key algorithm is SHA1withRSA
Try use 7za to compress the patch file: patch_signed_7zip.apk, will cost much more time
Current 7za path:/Users/muyang/.gradle/caches/modules-2/files-2.1/com.tencent.mm/SevenZip/1.1.10/cc390e6c704b74496d9ba0e9b46d2cf8a2a96b84/SevenZip-1.1.10-osx-x86_64.exe
Result: final signed patch result: /Users/muyang/code-demo/TinkerDemo/app/build/outputs/apk/tinkerPatch/release/patch_signed.apk, size=3538
Result: final signed with 7zip patch result: /Users/muyang/code-demo/TinkerDemo/app/build/outputs/apk/tinkerPatch/release/patch_signed_7zip.apk, size=3917
Warning: patch_signed_7zip.apk is bigger than patch_signed.apk 379 byte, you should choose patch_signed.apk at these time!
Tinker patch done, total time cost: 2.350000s
Tinker patch done, you can go to file to find the output /Users/muyang/code-demo/TinkerDemo/app/build/outputs/apk/tinkerPatch/release
-----------------------Tinker patch end-------------------------
2、在Bugly热更新后台上传补丁包时,提示如下:
三、求助:
纠结的是不知道在哪里去配置这些参数了?如有大神路过,万望指点一二,不胜感激!
四、已找到问题原因:
如图,执行buildTinkerPatchRelease时,需要是在app目录下的tasks目录中的tinker-support中,而不是直接在Tasks目录中的tinker-support中。