Summary of Tinker integration practice of Android hot update open source project

preface

Recently, Tinker was integrated into the project. At first, I thought that the integration would be relatively simple, but I still encountered some problems in the actual operation. This article will introduce the main problems we will encounter in the integration process.

Consideration 1: background selection

At present, the background function can be realized in three ways:

1. Build their own background pudding distribution system

2. The services provided by third parties, such as the personal tinkerpatch platform of the original wechat Simsun God, are currently in the internal testing stage and are temporarily free of charge. In the later stage, the app should be charged according to the volume.

3. The service provided by Tencent bugly provides a hot update distribution background, which is integrated into bugly's upgrade SDK. free

According to the spirit of the company, we chose bugly as our scheme, which everyone knows.

Consideration 2: multi-channel packaging

We have nearly 100 channels. Each channel needs a different channel number. The DEX of the package printed by product flavor is different. In this way, 100 patches are required for the hot update of 100 channel packages, which is a disaster for management. Tinker also gives a recommended solution to this problem, that is, using the open source project packer ng plugin. Its principle is to write the channel information in the zip comment of the APK file, so that the content of DEX will not be affected during multi-channel packaging.

Consideration 3: problems caused by resource confusion

At present, the project uses the resource obfuscation project andresguard. For the introduction of andresguard, please refer to the document andresguard [Android obfuscation tool andresguard].

It also introduces resource confusion. Both hot update and multi-channel packaging must rely on the APK package generated after resource confusion. So we integrated the compilation process.

**Before integration**

Compilation: the compilation can be directly generated by using the command resguarderelease provided by andresguard. The APK file generated by resguardrelease is resource free.

./gradlew resguardRelease

Tinker generates a patch: the release file generated by directly calling the tinkerpatchrelease task does not confuse resources

./gradlew tinkerPatchRelease

Multi channel packaging: use the packer ng command apkrelease to generate multi-channel files without resource confusion

./gradlew apkRelease

**After integration**

It mainly solves two problems:

1. Tinker needs to use the APK after resource confusion to generate the original and new APK of the patch

2. The original APK used for multi-channel packaging needs to use the APK after resource confusion

For question 1:

When compiling with resguarderelease, after the compilation, copy the generated APK file, R file, map file and resource map file to the ${builddir} / bakapk / resguard directory;

When using tinkerpatchrelease to generate patches, add the resguardtask task before the tinkerpatchrelease task, so that the old and new apks used in generating patches are confused with resources. The gradle code of the core is as follows:

To solve problem 2, the way of using apkrelease task packaging in as is no longer applicable. You can directly use the command line method provided by packer ng to generate channel packages. After testing, 100 channel packages can be completed in about 10s, which is quite fast. Considering that the marketing personnel will play different channel packages, a simple tool can be provided to the marketing personnel in the later stage.

Post consolidation operations:

compile:

./gradlew resguardRelease

The generated APK file is placed in the ${app} \ build \ bakapk \ resguard \ directory

Patching:

The final generated patch is placed in the ${app} \ build \ outputs \ patch \ directory

Multi channel packaging:

For the package generated after compilation, you can use the command line provided by packer ng

java -jar PackerNg-x.x.x.jar apkFile marketFile outputDir

The above is the whole content of this article. I hope the content of this article can bring some help to your study or work. At the same time, I also hope to support a lot of programming tips!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>