Top Related Projects
Nuwa, pure java implementation, can hotfix your android application.
dexposed enable 'god' mode for single android application.
another hotfix framework
Robust is an Android HotFix solution with high compatibility and high stability. Robust can fix bugs immediately without a reboot.
Tinker is a hot-fix solution library for Android, it supports dex, library and resources update without reinstall apk.
A hotfix library for Android platform, and not just this...
Quick Overview
AndFix is an open-source library developed by Alibaba that allows developers to patch Android applications at runtime, without the need to re-install the app. This can be particularly useful for quickly fixing critical bugs or security vulnerabilities in deployed applications.
Pros
- Runtime Patching: AndFix enables developers to patch Android apps without requiring users to update or re-install the application.
- Compatibility: The library supports a wide range of Android versions, from Android 2.3 (Gingerbread) to the latest versions.
- Performance: AndFix patches are applied quickly, with minimal impact on the app's performance.
- Ease of Use: The library provides a simple and straightforward API for integrating runtime patching into Android apps.
Cons
- Complexity: Integrating AndFix into an existing Android app may require some additional complexity and setup.
- Potential Security Risks: Allowing runtime patching of an app could potentially introduce security vulnerabilities if not implemented correctly.
- Limited Scope: AndFix is primarily focused on fixing bugs and vulnerabilities, and may not be suitable for more complex app updates or feature changes.
- Dependency on Alibaba: As an Alibaba-developed project, AndFix may be subject to the company's long-term support and development plans.
Code Examples
Here are a few examples of how to use the AndFix library in your Android app:
Applying a Patch
// Create a new patch
Patch patch = new Patch();
// Add the patch to the PatchManager
PatchManager.getInstance().addPatch(patch);
// Apply the patch
PatchManager.getInstance().applyPatch();
This code demonstrates how to create a new patch, add it to the PatchManager
, and apply the patch to the running application.
Registering a Patch Listener
// Register a patch listener
PatchManager.getInstance().addPatchListener(new PatchListener() {
@Override
public void onPatchApplied(Patch patch) {
// Handle the successful patch application
}
@Override
public void onPatchFailed(Patch patch, Throwable throwable) {
// Handle the failed patch application
}
});
This code demonstrates how to register a PatchListener
to receive notifications when a patch is applied successfully or fails.
Uninstalling a Patch
// Uninstall a patch
PatchManager.getInstance().removePatch(patch);
This code shows how to uninstall a previously applied patch.
Getting Started
To get started with AndFix, follow these steps:
- Add the AndFix dependency to your app's
build.gradle
file:
dependencies {
implementation 'com.alipay.euler:andfix:0.5.0'
}
- Initialize the
PatchManager
in your application'sonCreate()
method:
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
PatchManager.getInstance().init(this);
}
}
- Create a new patch and add it to the
PatchManager
:
Patch patch = new Patch();
patch.setPatchFile(new File("/path/to/patch.apatch"));
PatchManager.getInstance().addPatch(patch);
- Apply the patch to the running application:
PatchManager.getInstance().applyPatch();
That's the basic setup to get started with AndFix. You can refer to the project's README for more detailed instructions and advanced usage examples.
Competitor Comparisons
Nuwa, pure java implementation, can hotfix your android application.
Pros of Nuwa
- Supports both Java and native code patching
- Allows for more complex modifications, including adding new methods and classes
- Provides a more flexible patching mechanism
Cons of Nuwa
- More complex implementation and usage compared to AndFix
- Potentially higher performance overhead due to its more comprehensive patching capabilities
Code Comparison
AndFix:
import com.alipay.euler.andfix.patch.PatchManager;
PatchManager patchManager = new PatchManager(context);
patchManager.init(appVersion);
patchManager.loadPatch();
Nuwa:
import cn.jiajixin.nuwa.Nuwa;
Nuwa.init(this);
Nuwa.loadPatch(this, patchFile);
Both AndFix and Nuwa are Android hot-fix solutions that allow developers to patch bugs in live applications without requiring users to update the entire app. AndFix, developed by Alibaba, focuses on simplicity and speed, primarily targeting method-level fixes. Nuwa, on the other hand, offers a more comprehensive patching solution, supporting both Java and native code modifications.
While AndFix is easier to implement and may have a lower performance impact, Nuwa provides greater flexibility in the types of patches that can be applied. However, this flexibility comes at the cost of increased complexity and potentially higher overhead.
The code comparison shows that both libraries have a relatively simple API for initialization and patch loading, with Nuwa's implementation being slightly more concise.
dexposed enable 'god' mode for single android application.
Pros of dexposed
- More flexible and powerful, allowing for method hooking and modification
- Supports a wider range of Android versions (2.3 to 12)
- Can be used for runtime analysis and debugging
Cons of dexposed
- More complex to implement and use
- Potentially higher performance overhead
- May require more maintenance due to its broader scope
Code Comparison
dexposed:
DexposedBridge.hookMethod(Method method, XC_MethodHook callback);
AndFix:
AndFix.addPatch(Context context, String patchPath);
Key Differences
- dexposed focuses on method hooking and modification, while AndFix is primarily for hot patching
- dexposed offers more flexibility but may be more complex to use
- AndFix is designed specifically for quick bug fixes, while dexposed has broader applications
Use Cases
- dexposed: Runtime analysis, debugging, and advanced app modifications
- AndFix: Quick deployment of critical bug fixes without app updates
Community and Maintenance
Both projects are maintained by Alibaba, but dexposed has more recent updates and a larger community following. AndFix, while still useful, has seen less recent development activity.
Performance Considerations
AndFix generally has lower performance overhead, as it's designed for targeted patching. dexposed may have a more noticeable impact on app performance, especially when hooking multiple methods.
another hotfix framework
Pros of RocooFix
- Supports both Java and Native code hotfixing
- Allows for more complex patches, including structural changes
- Better compatibility with Android ART runtime
Cons of RocooFix
- More complex setup and integration process
- Potentially larger patch sizes
- May require more careful management of patch versions
Code Comparison
AndFix patch application:
AndFix.addPatch(context, path);
RocooFix patch application:
RocooFix.applyPatch(context, path);
RocooFix.initPathFromAssets(context, "patch.jar");
Both AndFix and RocooFix are Android hotfix libraries designed to patch bugs in live applications without requiring a full app update. AndFix, developed by Alibaba, focuses on simplicity and speed, while RocooFix offers more flexibility and broader compatibility.
RocooFix provides support for both Java and Native code fixes, making it more versatile for complex applications. It also handles structural changes better, allowing for more comprehensive patches. However, this flexibility comes at the cost of a more complex setup process and potentially larger patch sizes.
AndFix, on the other hand, is known for its simplicity and smaller patch sizes, but it may have limitations when dealing with more complex fixes or certain Android runtime environments.
When choosing between the two, developers should consider their specific needs, the complexity of their application, and the types of fixes they anticipate needing in the future.
Robust is an Android HotFix solution with high compatibility and high stability. Robust can fix bugs immediately without a reboot.
Pros of Robust
- Supports a wider range of Android versions (2.3+) compared to AndFix's limited range
- Offers more comprehensive patching capabilities, including resources and so files
- Provides better compatibility with different Android devices and architectures
Cons of Robust
- More complex implementation and integration process than AndFix
- Larger patch size due to its comprehensive nature
- Potentially higher performance overhead for some operations
Code Comparison
AndFix patch application:
AndFix.addPatch(context, path);
Robust patch application:
PatchExecutor patchExecutor = new PatchExecutor(context, patch, new PatchCallback() {
@Override
public void onPatchSuccess() {
// Handle success
}
});
patchExecutor.start();
Both AndFix and Robust aim to provide hot-fixing solutions for Android applications, but they differ in their approach and capabilities. AndFix focuses on simplicity and speed, while Robust offers more comprehensive patching at the cost of increased complexity. The choice between the two depends on the specific requirements of the project and the level of patching flexibility needed.
Tinker is a hot-fix solution library for Android, it supports dex, library and resources update without reinstall apk.
Pros of Tinker
- More comprehensive patching capabilities, supporting resources, assets, and native libraries
- Better compatibility across different Android versions and devices
- Supports multidex applications and complex project structures
Cons of Tinker
- More complex integration process and larger patch sizes
- Requires more setup and configuration compared to AndFix
- Potentially longer patch application time due to its comprehensive nature
Code Comparison
AndFix patch application:
AndFix.addPatch(context, patchFile.getAbsolutePath());
Tinker patch application:
TinkerInstaller.onReceiveUpgradePatch(getApplicationContext(), patchPath);
Key Differences
- Scope: AndFix focuses on method-level hotfixing, while Tinker offers full APK patching.
- Performance: AndFix is generally faster in applying patches due to its limited scope.
- Flexibility: Tinker provides more options for customization and handling complex scenarios.
- Maintenance: AndFix is no longer actively maintained, while Tinker receives regular updates.
Use Cases
- AndFix: Quick fixes for critical bugs in production, especially when minimal app size increase is crucial.
- Tinker: Comprehensive app updates, including resources and libraries, suitable for larger-scale modifications.
A hotfix library for Android platform, and not just this...
Pros of Amigo
- Supports full APK replacement, allowing for more comprehensive updates
- Provides a more flexible patching mechanism, enabling changes to resources and assets
- Offers better compatibility with Android's ART runtime
Cons of Amigo
- Larger patch size due to full APK replacement
- More complex implementation and integration process
- Potentially longer application startup time
Code Comparison
AndFix patch application:
AndFix.addPatch(path);
Amigo patch application:
Amigo.getInstance(this).applyPatch(path);
Key Differences
AndFix focuses on method-level hotfixing, making it lightweight and fast to apply. It's suitable for quick, small fixes but has limitations in terms of what can be patched.
Amigo, on the other hand, replaces the entire APK, allowing for more comprehensive updates. This approach provides greater flexibility but comes at the cost of larger patch sizes and potentially longer application times.
Both solutions aim to provide hot-fixing capabilities for Android apps, but they differ in their approach and use cases. AndFix is better suited for rapid, small fixes, while Amigo is more appropriate for larger, more complex updates that may involve changes to resources or the app structure.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
AndFix
AndFix is a solution to fix the bugs online instead of redistributing Android App. It is distributed as Android Library.
Andfix is an acronym for "Android hot-fix".
AndFix supports Android version from 2.3 to 7.0, both ARM and X86 architecture, both Dalvik and ART runtime, both 32bit and 64bit.
The compressed file format of AndFix's patch is .apatch. It is dispatched from your own server to client to fix your App's bugs.
Principle
The implementation principle of AndFix is method body's replacing,
Method replacing
AndFix judges the methods should be replaced by java custom annotation and replaces it by hooking it. AndFix has a native method art_replaceMethod
in ART or dalvik_replaceMethod
in Dalvik.
For more details, here.
Fix Process
Integration
How to get?
Directly add AndFix aar to your project as compile libraries.
For your maven dependency,
<dependency>
<groupId>com.alipay.euler</groupId>
<artifactId>andfix</artifactId>
<version>0.5.0</version>
<type>aar</type>
</dependency>
For your gradle dependency,
dependencies {
compile 'com.alipay.euler:andfix:0.5.0@aar'
}
How to use?
- Initialize PatchManager,
patchManager = new PatchManager(context);
patchManager.init(appversion);//current version
- Load patch,
patchManager.loadPatch();
You should load patch as early as possible, generally, in the initialization phase of your application(such as Application.onCreate()
).
- Add patch,
patchManager.addPatch(path);//path of the patch file that was downloaded
When a new patch file has been downloaded, it will become effective immediately by addPatch
.
Developer Tool
AndFix provides a patch-making tool called apkpatch.
How to get?
The apkpatch
tool can be found here.
How to use?
-
Prepare two android packages, one is the online package, the other one is the package after you fix bugs by coding.
-
Generate
.apatch
file by providing the two package,
usage: apkpatch -f <new> -t <old> -o <output> -k <keystore> -p <***> -a <alias> -e <***>
-a,--alias <alias> keystore entry alias.
-e,--epassword <***> keystore entry password.
-f,--from <loc> new Apk file path.
-k,--keystore <loc> keystore path.
-n,--name <name> patch name.
-o,--out <dir> output dir.
-p,--kpassword <***> keystore password.
-t,--to <loc> old Apk file path.
Now you get the application savior, the patch file. Then you need to dispatch it to your client in some way, push or pull.
Sometimes, your team members may fix each other's bugs, and generate not only one .apatch
. For this situation, you can
merge .apatch
files using this tool,
usage: apkpatch -m <apatch_path...> -o <output> -k <keystore> -p <***> -a <alias> -e <***>
-a,--alias <alias> keystore entry alias.
-e,--epassword <***> keystore entry password.
-k,--keystore <loc> keystore path.
-m,--merge <loc...> path of .apatch files.
-n,--name <name> patch name.
-o,--out <dir> output dir.
-p,--kpassword <***> keystore password.
Running sample
- Import samplesI/AndFixDemo to your IDE, append AndFixDemo dependencies with AndFix(library project or aar).
- Build project, save the package as 1.apk, and then install on device/emulator.
- Modify com.euler.test.A, references com.euler.test.Fix.
- Build project, save the package as 2.apk.
- Use apkpatch tool to make a patch.
- Rename the patch file to out.apatch, and then copy it to sdcard.
- Run 1.apk and view log.
Notice
ProGuard
If you enable ProGuard, you must save the mapping.txt, so your new version's build can use it with "-applymapping".
And it is necessary to keep classes as follow,
-
Native method
com.alipay.euler.andfix.AndFix
-
Annotation
com.alipay.euler.andfix.annotation.MethodReplace
To ensure that these classes can be found after running an obfuscation and static analysis tool like ProGuard, add the configuration below to your ProGuard configuration file.
-keep class * extends java.lang.annotation.Annotation
-keepclasseswithmembernames class * {
native <methods>;
}
Self-Modifying Code
If you use it, such as Bangcle. To generate patch file, you'd better to use raw apk.
Security
The following is important but out of AndFix's range.
- verify the signature of patch file
- verify the fingerprint of optimize file
API Documentation
The libraries javadoc can be found here.
Contact
...
License
Copyright (c) 2015, alipay.com
Top Related Projects
Nuwa, pure java implementation, can hotfix your android application.
dexposed enable 'god' mode for single android application.
another hotfix framework
Robust is an Android HotFix solution with high compatibility and high stability. Robust can fix bugs immediately without a reboot.
Tinker is a hot-fix solution library for Android, it supports dex, library and resources update without reinstall apk.
A hotfix library for Android platform, and not just this...
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot