Android Tinker热更新的集成教程
1.创建项目与集成所需类库
在工程的gradle中:classpath ('com.tencent.tinker:tinker-patch-gradle-plugin:1.7.7')
在项目的gradle中:
compile('com.tencent.tinker:tinker-android-lib:1.7.7') { changing =true}
provided('com.tencent.tinker:tinker-android-anno:1.7.7') { changing =true}
compile'com.android.support:multidex:1.0.1'
2.写一个application的代理类
@SuppressWarnings("unused")
@DefaultLifeCycle(application ="com.meng.app.AppApplication",
flags = ShareConstants.TINKER_ENABLE_ALL,
loadVerifyFlag =false)
public classApplicationLikeextendsDefaultApplicationLike {
publicApplicationLike(Application application,inttinkerFlags,booleantinkerLoadVerifyFlag,longapplicationStartElapsedTime,longapplicationStartMillisTime, Intent tinkerResultIntent) {
super(application, tinkerFlags, tinkerLoadVerifyFlag, applicationStartElapsedTime, applicationStartMillisTime, tinkerResultIntent);
}
/**
* install multiDex before install tinker
* so we don't need to put the tinker lib classes in the main dex
*
*@parambase
*/
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
@Override
public voidonBaseContextAttached(Context base) {
super.onBaseContextAttached(base);
//you must install multiDex whatever tinker is installed!
MultiDex.install(base);
//installTinker after load multiDex
//or you can put com.tencent.tinker.** to main dex
TinkerInstaller.install(this);
}
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public voidregisterActivityLifecycleCallbacks(Application.ActivityLifecycleCallbacks callback) {
getApplication().registerActivityLifecycleCallbacks(callback);
}
}
现在编译会报错,需要配置
3. build.gradle的配置
3.构建app签名
4.编写测试类
5.运行测序到手机
6.配置补丁文件
替换为一致的7.更改测试代码
7.生成补丁文件
8.获取补丁
9.把补丁拷贝到内存卡根目录
10.重新打开app,可能会闪退,第二次进入,更新成功
github:https://github.com/LostDeer/Tinker