This article uses Tinker as the hotfix tool and Bugly as the background for the patch.

Introduction to Tinker and Bugly

“Tinker” is the official wechat Hot patch solution for Android, which supports dynamic distribution of code, So library and resources, used to fix bugs and solve your urgent need.

“Bugly” is a platform of Tencent for bug management, operation statistics and hot repair of mobile terminals.

Tinker hotfix GitHub link address.

See the project Wiki link for instructions and an introduction.

For details, see GitHub link address.

Bugly Android Hot Update user guide link address.

Bugly and Tinker access

Refer to the “Bugly Android Hot Update Guide” above and follow the steps step by step. A few points should be noted:

  1. When configuring dependencies, it is best to specify a version number. Because if something changes in the latest version and you don’t know about it, there may be some problems, such as the name of the method is changed and you can’t find it when you upgrade.

  2. If you have connected to Bugly before, you need to comment out the bugly dependencies in Gradle.

  3. Don’t forget to add plugin dependencies to the ‘build.gradle’ file of App Modul E.

    apply from: 'tinker-support.gradle'

  4. Use the recommended Tinker access mode, although access trouble to write, but better compatibility.

Here’s a detailed description of the recommended Tinker access method, which is confusing for many people.

  1. Change the inherited Application in BaseApplication to inherit DefaultApplicationLike, and import the constructor.
  2. Added in the BaseApplication onBaseContextAttached () method and registerActivityLifecycleCallback () method.
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) @Override public void onBaseContextAttached(Context base) { super.onBaseContextAttached(base); // you must install multiDex whatever tinker is installed! MultiDex.install(base); // installTinker beta.installtinker (this); } @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) public void registerActivityLifecycleCallback(Application.ActivityLifecycleCallbacks callbacks) { getApplication().registerActivityLifecycleCallbacks(callbacks); }Copy the code
  1. Initialize Bugly in the onCreate method.
    @Override
    public void onCreate() { super.onCreate(); // When debugging, change the third parameter to Buglytrue
        Bugly.init(getApplication(), "900029763".false);
    }
Copy the code

At this point, our original BaseApplication has been transformed. The Application can be obtained by getApplication().

  1. Custom Application inherits TinkerApplication.
public class SampleApplication extends TinkerApplication {
    public SampleApplication() {
        super(ShareConstants.TINKER_ENABLE_ALL, "xxx.xxx.SampleApplicationLike"."com.tencent.tinker.loader.TinkerLoader".false); }}Copy the code

The second parameter “XXX, XXX. SampleApplicationLike,” is that we just change a good BaseApplication, XXX, XXX is your package name of the project.

  1. Change the application name in androidmanifest.xml to the custom application.

As for the tinker-support.gradle file, we can paste it directly. For details about the configuration parameters, see the TinkerSupport plug-in Usage guide.

Official release:

  1. You can also use global search by opening the tinker-support.gradle file under the main moudle of your project. This file is tinker’s configuration file. Hotfix related functions and parameters can be configured in this file.

  2. Open the Tinker hotfix component. In the tinkerSupport method, change enable to true.

    Enable = true (true enables, false disables).

  3. Enable the overwriting tinkerPatch configuration function. In tinkerSupport method, will overrideTinkerPatchConfiguration to true.

    OverrideTinkerPatchConfiguration = true (true open, shut false).

  4. Configure the tinkerId according to the rules. The tinkerId must be unique.

  • Official package Base-version Name For example, base-2.6.1
  • Patch package patch-version 1 Example: patch-2.6.1.1 patch-2.6.1.2…
  1. Disable the tinkerPatch function. Note tinkerEnable = false in tinkerPatch.

    //tinkerEnable = false

  2. After modifying these configurations, you can package them in either of the following ways.

  • Build -> Generate Signed APK

  • Open the Gradle file and run the project Gradle -> Tasks -> Build -> assembleRelease.

After gradle runs, bakApk folder will be generated. App-mmdd-hh-mm-ss in this folder is our base package directory, which will be used in the later patch package, so it must be saved well.

File location: project master moudle -> build -> bakApk -> app-mmDD-HH-mm-ss (generated according to time).

App-release. apk is the package we made, and it can be online after strengthening with 360 reinforcement assistant.

Release patch packs:

When you fix the bug,

  1. Modify the base package directory. In tinker-support.gradle, change def baseApkDir to the base directory for the version you need to fix (that is, the base directory mentioned above).

    def baseApkDir = "app-MMdd-hh-mm-ss"

    Mmdd-hh-mm-ss change to the base package directory for the version you need to fix

The following 5 steps are the same as the first 5 steps of sending formal packages. Remember to modify tinkerId, otherwise there will be no identified version.

  1. Build the patch package using buildTinkerPatchRelease.

Open Gradle and run the project gradle -> Tasks -> Tinker-support -> buildTinkerPatchRelease.

If this option is not available, first verify that your tinkerEnable is true and then rebuild the project.

  1. Use the Bugly platform to deliver patch packages.

After gradle finishes running, a new base package will be generated, and the repaired APK will be in this file. At the same time, the patch folder is also generated, and the patch patch_SIGned_7zip. apk is in this folder.

Patch file location: project owner moudle -> build -> outputs -> Patch -> Release.

Open the Bugly platform and choose Mobile Platform -> App Upgrade -> Hot Update.

Click Publish patch and select patch file. The target version will be matched automatically after the patch is uploaded. You can select a delivery range.

Use the Instantrun configuration

Since Android Studio instantrun and Tinker both conflict, tinker must be disabled to use instantTun.

1. Disable the Tinker hot repair component. In the tinkerSupport method, change enable to false.

Enable = false(true enables, false disables)

2. Disable the tinkerPatch overwriting function. In tinkerSupport method, change the overrideTinkerPatchConfiguration to false.

OverrideTinkerPatchConfiguration = false (true open, shut false).

3. Enable tinkerPatch. In tinkerPatch, remove the tinkerEnable = false comment in tinkerPatch.

tinkerEnable = false

Then instantrun can be used as normal.


Copyright statement: this article for the blogger original articles, can be reprinted, reproduced indicate the source: https://juejin.im/editor/drafts/5aca25d2518825555e5e1f44.