Giter Site home page Giter Site logo

android-hotpatch's Introduction

Android-Hotpatch

Github All Releases license gitcheese.com

Update or fix an android app on the fly, without having to publish a new APK.

Usage:

  1. Make a .jar library with your app's classes and methods that you want to be updatable (see compiling your application as a library)
  2. Grab Hotpatch.java and add it to your project
  3. Load the .jar library you built earlier

You might need to do a small refactor of your app's code, but the advantages are many:

  • Quickly fix & deploy a patch for a method
  • Add methods to classes
  • Hotpatch does not need the app to restart
  • Updating an app using Hotpatch does not require root!

Quick usage demo:

Let's say we have a class that we want to use in our Android app, defined this way:

package com.chars.testlib.TestLib;

public class TestLib {
     public String getVersionString() {
        return "libversion 1.0";
     }
}

After making a .jar library of that class, deploy it to you device i.e in /sdcard/TestLib.jar

In order to use it in your Android app, you must load it with Hotpatch

final String className = "com.chars.testlib.TestLib";
final String methods[] = {"getVersionString"};

final Hotpatch hotpatch = new Hotpatch();

try {
    hotpatch.loadLibrary("/sdcard/TestLib.jar", getApplicationContext());
    hotpatch.loadClass(className);
    hotpatch.loadMethods(className, methods);

    String result = (String)hotpatch.call(className, methods[0]);
    Log.d("AndroidHotpatch", result);

} catch (Exception e) {
    Log.e("AndroidHotpatch", Log.getStackTraceString(e));
}

The line

    String result = (String)hotpatch.call(className, methods[0]);

will execute the getVersionString() method, defined in class TestLib.

To update the library, just make a new .jar from an updated version of the class. For example:

package com.chars.testlib.TestLib;

public class TestLib {
     public String getVersionString() {
        return "libversion 2.0";
     }
}

Push the updated .jar to the same path as the previous. In your Android app, you can just call

    hotpatch.reload();

and you'll have your updated library loaded into the app. Now, whenever you execute getVersionString() you will get "libversion 2.0"

Compiling an application as a library (Android Studio / Eclipse):

  1. Start a new android project
  2. Add the classes that you want to be updatable
  3. Build an APK
  4. Rename the .apk file to .jar

Changelog

  • v0.1 Alpha:
    • Support for methods
    • Implemented Hotpatch.loadLibrary()
    • Implemented Hotpatch.loadClass()
    • Implemented Hotpatch.loadMethods()
    • Implemented Hotpatch.reload()
    • Implemented Hotpatch.call()

android-hotpatch's People

Contributors

carloalbertobarbano avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.