android 微信热修复Tinker接入过程以及使用方法
来源:互联网 发布:手机相片制作软件 编辑:程序博客网 时间:2024/06/05 10:11
github : https://github.com/Tencent/tinker
1 添加依赖
compile('com.tencent.tinker:tinker-android-anno:1.6.2')compile('com.tencent.tinker:tinker-android-lib:1.6.2')
根目录配置文件添加tinker的gradle插件classpath ('com.tencent.tinker:tinker-patch-gradle-plugin:1.6.2')
2 添加(或修改)项目的 Application ,使之继承DefaultApplicationLike; 这块有点奇葩,这个DefaultApplicationLike不是继承自Application,需要用注解来设置项目中真正的Application,Tinker插件会自动生成真正的Application
@DefaultLifeCycle( application = "ook.yzx.tinker.Application", flags = ShareConstants.TINKER_ENABLE_ALL)public class MyApplication extends DefaultApplicationLike{ public MyApplication(Application application, int tinkerFlags, boolean tinkerLoadVerifyFlag, long applicationStartElapsedTime, long applicationStartMillisTime, Intent tinkerResultIntent, Resources[] resources, ClassLoader[] classLoader, AssetManager[] assetManager) { super(application, tinkerFlags, tinkerLoadVerifyFlag, applicationStartElapsedTime, applicationStartMillisTime, tinkerResultIntent, resources, classLoader, assetManager); }}上边的"ook.yzx.tinker.Application"就是真正的Application,不用我们自己写,是自动生成的;然后修改manifest.xml将application指向ook.yzx.tinker.Application就行,开始会报错,build一下项目就好了;
3 在build.gradle中的最外层添加下边的配置,这些个配置的意义可以看:tinker接入指南 ; 这些配置是从demo中挑出来的,有的配置也不是必须的;
apply plugin: 'com.tencent.tinker.patch'tinkerPatch { //有问题的apk的地址 oldApk = "D://app_bug.apk" ignoreWarning = false useSign = true buildConfig{ tinkerId = "1.0" } packageConfig{ //写这个为了修复一个bug,详见github issue #22 configField("TINKER_ID", "1.0") } dex{ dexMode = "jar" pattern = ["classes*.dex", "assets/secondary-dex-?.jar"] loader = ["com.tencent.tinker.loader.*", "ook.yzx.tinker.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" }
}
4 java代码中的使用
首先是初始化 :在继承DefaultApplicationLike的类中重写onBaseContextAttached方法,然后在super之后执行TinkerInstaller.install(this)就行了;
然后是安装补丁 : 当补丁从自己的服务器下载好后, 执行
TinkerInstaller.onReceiveUpgradePatch(this.getApplication(), Environment.getExternalStorageDirectory().getAbsolutePath()+"/patch.xxx");
详细见 : Tinker API概览;
PS:那个github上的demo写的真是墨墨迹迹的,各种和核心没用的代码,就这么几个主要的API,愣是写了那么一堆
5 现在万事俱备,就差执行了 ;
大概测试步骤 : 写一个Activity
public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TinkerInstaller.onReceiveUpgradePatch(this.getApplication(), Environment.getExternalStorageDirectory().getAbsolutePath()+"/a1"); Toast.makeText(this, "错误的 !!!!! ~", Toast.LENGTH_SHORT).show(); }}然后打包;生成一个apk,安装到手机,在拷贝一份到oldApk指定的目录(我的是D://app_bug.apk);
然后修改Toast的内容为其他的,打开android studio的底下的terminal标签卡(使用cmd也行), cd到对应的module文件夹下边,执行命令:gradle tinkerPatchRelease,然后是一顿等,第一次会慢点因为要下载一堆东西;之后会在build文件夹下生成一个outputs/tikerPatch文件夹,里边就是补丁文件以及其他的一些有用的文件,详见github的文档说明;将补丁文件放到手机中对应的地方后,打开一次app,然后kill掉,在打开,就变了...
6 Tinker的接入比较墨迹,研究AndFix时候用了一小时左右就能接入成功, 这玩意浪费了一下午才完事,主要是github上有一个issue22比较坑爹...
demo地址 : http://download.csdn.net/detail/a750457103/9657279
4 0
- android 微信热修复Tinker接入过程以及使用方法
- android 微信热修复Tinker接入过程以及使用方法
- Android 微信热修复 Tinker 接入过程及使用方法
- Android 热修复 Tinker接入
- Android 热修复 Tinker 接入
- Android 热修复Tinker接入实战
- Android热修复框架 Tinker 接入
- Android热修复之Tinker接入流程
- Android 热修复 Tinker接入方法
- 微信热修复tinker及tinker server快速接入
- Android 浅尝Tinker微信热修复
- Android 笔记 :Android 热修复 Tinker接入及源码浅析
- Android 热修复 Tinker接入及源码浅析
- Android 热修复 Tinker接入及源码浅析
- Android 热修复 Tinker接入及源码浅析
- Android 热修复 Tinker接入及源码浅析
- Android 热修复 Tinker接入及源码浅析
- 初探Android热修复——tinker接入
- 前端ajax给springMVC传json格式字符串
- poj3468
- 计算机病毒的认识
- Zookeeper 安装和配置
- SWIG 和 Python——c/c++与脚本交互
- android 微信热修复Tinker接入过程以及使用方法
- BaseAdapter的三重境界,逗比式,普通式,文艺式
- 在多人同时登陆服务器的情况下单个用户被踢掉其桌面程序是否会关闭的问题
- 【图】犯罪团伙
- Android 同一个Service已经启动再多调用startService
- A gentle introduction to Tao.OpenGl using SimpleOpenGlControl.
- python中的排序
- POJ 1755 Triathlon I
- linux下安裝sougou拼音