/ | Tinker | QZone | AndFix | Robust |
---|---|---|---|---|
类替换 | yes | yes | no | no |
So替换 | yes | no | no | no |
资源替换 | yes | yes | no | no |
全平台支持 | yes | yes | yes | yes |
即时生效 | no | no | yes | yes |
性能损耗 | 较小 | 较大 | 较小 | 较小 |
补丁包大小 | 较小 | 较大 | 一般 | 一般 |
开发透明 | yes | yes | no | no |
复杂度 | 较低 | 较低 | 复杂 | 复杂 |
gradle支持 | yes | no | no | no |
Rom体积 | 较大 | 较小 | 较小 | 较小 |
成功率 | 较高 | 较高 | 一般 | 最高 |
dependencies {
classpath "com.tencent.tinker:tinker-patch-gradle-plugin:${TINKER_VERSION}"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
dependencies {
// 依赖multiDex库
compile 'com.android.support:multidex:1.0.1'
//可选,用于生成application类
provided ("com.tencent.tinker:tinker-android-anno:${TINKER_VERSION}"){changing = true}
//Tinker的核心库
compile ("com.tencent.tinker:tinker-android-lib:${TINKER_VERSION}"){changing = true}
}
apply plugin: 'com.tencent.tinker.patch'
tinkerPatch {
//有问题的apk的地址
oldApk = "F://app_bug.apk"
ignoreWarning = false
useSign = true
buildConfig{
tinkerId = "1.0"
}
packageConfig{
configField("TINKER_ID", "1.0")
}
dex{
dexMode = "jar"
pattern = ["classes*.dex", "assets/secondary-dex-?.jar"]
loader = ["com.tencent.tinker.loader.*", "com.tinkertest.Application"]
}
lib{
pattern = ["lib/armeabi/*.so","lib/arm64-v8a/*.so","lib/armeabi-v7a/*.so","lib/mips/*.so","lib/mips64/*.so","lib/x86/*.so","lib/x86_64/*.so"]
}
res{
pattern = ["res/*", "assets/*", "resources.arsc", "AndroidManifest.xml"]
largeModSize = 100
}
sevenZip{
zipArtifact = "com.tencent.mm:SevenZip:1.1.10"
}
1.写一个AppContextLike类继承自DefaultApplicationLike,并添加注解。使用注解生成application类AppContext,并且可以在这个类里面编写你原来Application需要实现的逻辑代码。
@DefaultLifeCycle(
application = ".AppContext",
flags = ShareConstants.TINKER_ENABLE_ALL,
loadVerifyFlag = false
)
public class AppContextLike extends DefaultApplicationLike {
public AppContextLike(Application application, int tinkerFlags, boolean tinkerLoadVerifyFlag, long applicationStartElapsedTime, long applicationStartMillisTime, Intent tinkerResultIntent) {
super(application, tinkerFlags, tinkerLoadVerifyFlag, applicationStartElapsedTime, applicationStartMillisTime, tinkerResultIntent);
}
@Override
public void onBaseContextAttached(Context base) {
super.onBaseContextAttached(base);
//必须安装MultiDex的更新!
MultiDex.install(base);
//安装Tinker后加载multiDex
TinkerManager.installTinker(this);
ApplicationContext.application = getApplication();
ApplicationContext.context = getApplication();
TinkerManager.setTinkerApplicationLike(this);
TinkerManager.initFastCrashProtect();
TinkerManager.setUpgradeRetryEnable(true);
}
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public void registerActivityLifecycleCallbacks(Application.ActivityLifecycleCallbacks callback) {
getApplication().registerActivityLifecycleCallbacks(callback);
}
}
2.添加到manifest中
**android:name=".tinker.AppContext"**
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
3.先将你的app运行到手机上并修改gradle里面oldapk的路径
4.修改app的代码,例如修改文字,Toast等,在实际中即修复bug。
5.在android-studio右边点开gradle窗口,选择tinkerPatchDebug,并运行生成补丁包
6.将补丁包放到手机的SD中
好啦,到这里微信热修复的集成就完成啦,如果有疑问,可以在下方留言,或者加我的QQ844974121 ,注明:微信热修复!
最后提醒大家不要忘记添加权限哦!(7.0的系统需要手动设置权限!)
https://github.com/mengjingbo/TinkerApp 源码demo