AndFix


Source link: https://github.com/alibaba/AndFix

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?

  1. Initialize PatchManager,
patchManager = new PatchManager(context);
 patchManager.init(appversion);
//current version
  1. Load patch,
patchManager.loadPatch();

You should load patch as early as possible, generally, in the initialization phase of your application(such as Application.onCreate()).

  1. 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

  1. Import samplesI/AndFixDemo to your IDE, append AndFixDemo dependencies with AndFix(library project or aar).
  2. Build project, save the package as 1.apk, and then install on device/emulator.
  3. Modify com.euler.test.A, references com.euler.test.Fix.
  4. Build project, save the package as 2.apk.
  5. Use apkpatch tool to make a patch.
  6. Rename the patch file to out.apatch, and then copy it to sdcard.
  7. 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

Apache License, Version 2.0

Copyright (c) 2015, alipay.com

Resources

Vidsta is a simple and easy to use video player, with customisable options for seamless integration. It's very lightweight, and features listeners for most possible events.

A sample app is also available.

Fast and simple Planning Poker Android app. Designed for phones, tablets and Android Wear devices.

A floating text button component.

Description is not available now, but it is coming soon!

Android animated recording view.

Animation that creates a pentagon shape with showing buttons on the click of floating action button. This project illustrated the use case of ValueAnimator and how to create and add views dynamically.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes