tinker

Tinker是Android的热修复解决方案库,它支持dex、库和资源更新,无需重新安装apk。(Tinker is a hot-fix solution library for Android, it supports dex, library and resources update without reinstall apk.)

Github星跟踪图

Tinker

Tinker是Android的热补丁解决方案库,它支持dex、库和资源更新,无需重新安装apk。

开始

在你的项目的根目录下,在主要的 build.gradle 中添加tinker-gradle-plugin作为依赖项:

buildscript {
    dependencies {
        classpath ('com.tencent.tinker:tinker-patch-gradle-plugin:1.9.1')
    }
}

然后,您需要“应用”插件,并通过将以下行添加到您的 app/build.gradle 中来添加依赖项。

dependencies {
    //optional, help to generate the final application 
    provided('com.tencent.tinker:tinker-android-anno:1.9.1')
    //tinker's main Android lib
    compile('com.tencent.tinker:tinker-android-lib:1.9.1')
}
...
...
apply plugin: 'com.tencent.tinker.patch'

如果您的应用程序有一个类android.app.Application的子类,那么您需要修改该类,并将其所有实现移至而不是Application:

-public class YourApplication extends Application {
+public class SampleApplicationLike extends DefaultApplicationLike {

现在,您应该更改您的 Application class,使其成为 TinkerApplication 的一个子类。正如你从API中看到的那样,它是一个没有默认构造函数的抽象类,所以你必须定义一个无参数构造函数:

public class SampleApplication extends TinkerApplication {
    public SampleApplication() {
      super(
        //tinkerFlags, which types is supported
        //dex only, library only, all support
        ShareConstants.TINKER_ENABLE_ALL,
        // This is passed as a string so the shell application does not
        // have a binary dependency on your ApplicationLifeCycle class. 
        "tinker.sample.android.app.SampleApplicationLike");
    }  
}

推荐使用 tinker-android-anno 来生成你的 Application ,你只需要为你的 SampleApplicationLike class 添加标注。

@DefaultLifeCycle(
application = "tinker.sample.android.app.SampleApplication",             //application name to generate
flags = ShareConstants.TINKER_ENABLE_ALL)                                //tinkerFlags above
public class SampleApplicationLike extends DefaultApplicationLike 

如何安装补丁程序?请通过示例 SampleApplicationLike 了解更多。

对于proguard,我们已经自动生成了proguard配置,并且tinker也会为您生成multiDex keep proguard文件。

有关更多补丁程序配置,请参阅示例app/build.gradle

已知问题

Tinker无法动态更新一些问题。

  1. 无法更新AndroidManifest.xml,例如添加Android组件。
  2. 不支持os版android-21的一些三星机型。
  3. 由于Google Play开发者分发协议,我们无法动态更新我们的apk。

支持

有问题吗?

  1. 了解更多有关tinker-sample-android 的资讯。
  2. 阅读源代码
  3. 阅读 wiki 常见问题解答寻求帮助。
  4. 联系请帮助我们。

贡献

有关提出问题或提出请求的更多信息,请参阅我们的 Tinker参与指南

许可证

补丁程序是在BSD许可下。详细信息请参阅许可证文件。

主要指标

概览
名称与所有者Tencent/tinker
主编程语言Java
编程语言Java (语言数: 5)
平台Android
许可证Other
所有者活动
创建于2016-09-06 06:57:52
推送于2025-09-10 11:52:42
最后一次提交2025-07-07 11:51:47
发布数76
最新版本名称v1.9.15.2 (发布于 2025-07-07 12:02:14)
第一版名称v1.2.0 (发布于 2016-07-26 23:54:50)
用户参与
星数17.6k
关注者数689
派生数3.4k
提交数861
已启用问题?
问题数1619
打开的问题数535
拉请求数73
打开的拉请求数14
关闭的拉请求数69
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?

Tinker

license
Release Version
PRs Welcome
WeChat Approved

Tinker is a hot-fix solution library for Android, it supports dex, library and resources update without reinstalling apk.

tinker.png

Getting started

Add tinker-gradle-plugin as a dependency in your main build.gradle in the root of your project:

buildscript {
    dependencies {
        classpath ('com.tencent.tinker:tinker-patch-gradle-plugin:1.9.1')
    }
}

Then you need to "apply" the plugin and add dependencies by adding the following lines to your app/build.gradle.

dependencies {
    //optional, help to generate the final application
    provided('com.tencent.tinker:tinker-android-anno:1.9.1')
    //tinker's main Android lib
    compile('com.tencent.tinker:tinker-android-lib:1.9.1')
}
...
...
apply plugin: 'com.tencent.tinker.patch'

If your app has a class that subclasses android.app.Application, then you need to modify that class, and move all its implements to SampleApplicationLike rather than Application:

-public class YourApplication extends Application {
+public class SampleApplicationLike extends DefaultApplicationLike {

Now you should change your Application class, make it a subclass of TinkerApplication. As you can see from its API, it is an abstract class that does not have a default constructor, so you must define a no-arg constructor:

public class SampleApplication extends TinkerApplication {
    public SampleApplication() {
      super(
        //tinkerFlags, which types is supported
        //dex only, library only, all support
        ShareConstants.TINKER_ENABLE_ALL,
        // This is passed as a string so the shell application does not
        // have a binary dependency on your ApplicationLifeCycle class.
        "tinker.sample.android.app.SampleApplicationLike");
    }
}

Use tinker-android-anno to generate your Application is recommended, you just need to add an annotation for your SampleApplicationLike class

@DefaultLifeCycle(
application = "tinker.sample.android.app.SampleApplication",             //application name to generate
flags = ShareConstants.TINKER_ENABLE_ALL)                                //tinkerFlags above
public class SampleApplicationLike extends DefaultApplicationLike

How to install tinker? learn more at the sample SampleApplicationLike.

For proguard, we have already made the proguard config automatic, and tinker will also generate the multiDex keep proguard file for you.

For more tinker configurations, learn more at the sample app/build.gradle.

Ark Support

How to run tinker on the Ark?

building patch

Just use the following command:

bash build_patch_dexdiff.sh old=xxx new=xxx
  • old indicates the absolute path of android apk(not compiled by Ark) with bugs
  • new indicates the absolute path of android apk(not compiled by Ark) with fixing

The patch file is packaged in APK.

compiling in Ark

TODO

At present it's compiled by Ark compiler team. The output patch is still packaged in APK format without signature.

packaging the patch

For tinker-cli, add the following lines to your tinker_config.xml. Otherwise, the default configure will be used.

<issue id="arkHot">
   <path value="arkHot"/>         // path of patch
   <name value="patch.apk"/>      // name of patch
</issue>

For gradle, add the following lines to your app/build.gradle. Otherwise, the default configure will be used.

ark {
   path = "arkHot"         // path of patch
   name = "patch.apk"      // name of patch
}

The patch is compiled by Ark and placed on the above path. all subsequent operations are same as tinker-cli or gradle.

The ultimated patch APK consists of two patch files:

  • classes.dex for android
  • patch.apk with so for Ark.

Tinker Known Issues

There are some issues which Tinker can't dynamic update.

  1. Can't update AndroidManifest.xml, such as add Android Component.
  2. Do not support some Samsung models with os version android-21.
  3. Due to Google Play Developer Distribution Agreement, we can't dynamic update our apk.

Tinker Support

Any problem?

  1. Learn more from tinker-sample-android.
  2. Read the source code.
  3. Read the wiki or FAQ for help.
  4. Contact us for help.

Contributing

For more information about contributing issues or pull requests, see our Tinker Contributing Guide.

License

Tinker is under the BSD license. See the LICENSE file for details.