tinker README

The project's README from github.com/Tencent/tinker. As one markdown file: README.md.

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

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:

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.

tinker (Tencent/tinker)

Searching Database…

17.7K ·GitHub
这是什么?Tinker 是一个 Android 热修复库,可以向用户推送 dex、原生库和资源的更新,而无需用户重新安装 APK。
这是独立的应用,还是要加到我自己项目里的东西?它是一个库加一个 Gradle 插件(tinker-gradle-plugin),需要集成到现有的 Android 应用构建中。
我该怎么把 Tinker 加到我的应用里?在根目录的 build.gradle 中添加 tinker-gradle-plugin,在 app/build.gradle 中应用插件并添加依赖;把你的 Application 子类逻辑迁移到 SampleApplicationLike 类中,并让真正的 Application 类继承 TinkerApplication,同时提供无参构造函数。
除了添加插件,我还需要别的东西吗?你需要一个可以重构的 Android Application 类;另外可以选择使用 tinker-android-anno 自动生成 Application 的相关配置。Proguard 配置由插件自动处理。
Tinker 不能热修复哪些内容?Tinker 无法更新 AndroidManifest.xml(例如新增组件);在部分运行 Android 21 的三星设备上存在问题;Google Play 的《开发者分发协议》禁止在该平台上进行动态 APK 更新。
这个面向哪个平台?仅支持 Android 应用,通过 Java/Gradle 构建。
README 里提到的 Ark 支持是什么?Ark 是一种编译模式:补丁通过命令行工具构建,并打包成一个同时包含 classes.dex(用于标准 Android)和 .so 文件(用于 Ark)的 APK,Ark 编译本身由 Ark 编译器团队负责。
不用 Gradle 也能构建和打包补丁吗?可以,tinker-cli 可以作为 Gradle 插件的替代方案使用,补丁配置还可以通过 tinkerconfig.xml 文件设置。
Creator
Tencent
Size
7.1 MB
Stars
17.7K
Age
10y
Commits · 90 Days