Another hotfix framework
The previous HotFix project was too simple, many students had problems with Nuwa, and the author did not fix them, so he rebuilt a set of tools.
Most of the features were copied from Nuwa and some of the bugs were fixed. I rewrote a RocooFix framework to solve the problem that Nuwa could not package the Transform API in Gradle Android 1.40. It is now compatible with Gradle 1.3-Gradle 2.1.0
Features
- Making patches is easier
- support
Com. Android. Tools. Build: gradle: 1.3.0
->Com. Android. Tools. Build: gradle: 2.1.0
(Solved the Nuwa problemissue) - Support obfuscation and Mulitdex
- Needed to pay attention to
hash.txt
andmapping.txt
File generation and saving
Use
public class RocooApplication extends Application { @Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); // Patch rocoofix.init (this); }}Copy the code
Configuration
Add the following configuration to your project’s build.gradle file
Rocoo_fix {includePackage = ['com/dodola/rocoofix']// excludeClass = [' baseApplication.class ']// Write classes that do not need to be added to the patch here preVersionPath = '1'// Note: this property needs to be enabled only for patch creation!! If you do not need to make patches, you need to remove this item enable = true// Note: If you turn this item off, you will not be able to generate hash.txt files}Copy the code
Here is a brief introduction to the preVersionPath property.
Rocoo_fix makes the patch creation process transparent. Users do not need to manually back up hash. TXT files. The plug-in automatically generates hash. TXT and mapping. TXT files to specified directories based on the current versionCode, for example:
In a release version number is 1, then the generated files will be placed on the app source directory/rocooFix version1 / / debug | release directory, if need to make patch in preVersionPath attributes specified in the configuration, Its value is the version number of the previous version, which in this case is 1,
Then change the versionCode number of build.gradle to 2, as long as it is different from the previous version, there is no specific value requirement
Proguard
-keep class com.dodola.rocoofix.** {*; }
Copy the code
Build Patch
The following shows the process of using project Demo to generate patches
package com.dodola.rocoosample; public class HelloHack { public String showHello() { return "hello world"; }}Copy the code
The VersionCode in build.gradle is 1
- Run the application once
app
The following files are generated in:
This can be seen as the hash.txt of our released version
- Suppose we need to fix step 1
showHello
Method, modified as follows:
package com.dodola.rocoosample; public class HelloHack { public String showHello() { return "hello Hack"; // This method returns hello hack}}Copy the code
- Modify the build.gradle file
rocoo_fix
To execute the Patch task. The configuration is as follows
Rocoo_fix {preVersionPath = '1'// Note: this specifies the VersionCode to be patched enable = true}Copy the code
- To modify the current project
versionCode
for2
, indicating that this is an upgrade fix version.
-
If the application is released normally, the patch file is generated in the following path:
-
We can decompile to make sure the patch works