Skip to content

Commit 71f2ae9

Browse files
Merging README changes
2 parents 414a343 + 0eadd2e commit 71f2ae9

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed

README.md

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,98 @@
11
# Android-Hotpatch
2+
[![Github All Releases](https://img.shields.io/github/downloads/charslab/Android-Hotpatch/total.svg)](https://github.com/charslab/Android-Hotpatch/releases)
3+
[![license](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/charslab/Android-Hotpatch/blob/master/LICENSE)
4+
5+
Update or fix an android app on the fly, without having to publish a new APK.
6+
7+
8+
## Usage:
9+
10+
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](https://github.com/charslab/Android-Hotpatch/blob/master/README.md#compiling-an-application-as-a-library-android-studio--eclipse))
11+
2. Grab [Hotpatch.java](https://github.com/charslab/Android-Hotpatch/blob/master/app/src/main/java/com/chars/android_hotpatch/Hotpatch.java) and add it to your project
12+
3. Load the .jar library you built earlier
13+
14+
You might need to do a small refactor of your app's code, but **the advantages are many:**
15+
16+
- Quickly fix & deploy a patch for a method
17+
- Add methods to classes
18+
- Hotpatch does not need the app to restart
19+
- Updating an app using Hotpatch **does not require root!**
20+
21+
22+
## Quick usage demo:
23+
24+
Let's say we have a class that we want to use in our Android app, defined this way:
25+
26+
```JAVA
27+
package com.chars.testlib.TestLib;
28+
29+
public class TestLib {
30+
public String getVersionString() {
31+
return "libversion 1.0";
32+
}
33+
}
34+
```
35+
36+
After making a .jar library of that class, deploy it to you device i.e in */sdcard/TestLib.jar*
37+
38+
In order to use it in your Android app, you must load it with Hotpatch
39+
40+
```JAVA
41+
final String className = "com.chars.testlib.TestLib";
42+
final String methods[] = {"getVersionString"};
43+
44+
final Hotpatch hotpatch = new Hotpatch();
45+
46+
try {
47+
hotpatch.loadLibrary("/sdcard/TestLib.jar", getApplicationContext());
48+
hotpatch.loadClass(className);
49+
hotpatch.loadMethods(className, methods);
50+
51+
String result = (String)hotpatch.call(className, methods[0]);
52+
Log.d("AndroidHotpatch", result);
53+
54+
} catch (Exception e) {
55+
Log.e("AndroidHotpatch", Log.getStackTraceString(e));
56+
}
57+
```
58+
59+
The line
60+
61+
String result = (String)hotpatch.call(className, methods[0]);
62+
63+
will execute the *getVersionString()* method, defined in class *TestLib*.
64+
65+
To update the library, just make a new .jar from an updated version of the class. For example:
66+
67+
```JAVA
68+
package com.chars.testlib.TestLib;
69+
70+
public class TestLib {
71+
public String getVersionString() {
72+
return "libversion 2.0";
73+
}
74+
}
75+
```
76+
Push the updated .jar to the same path as the previous. In your Android app, you can just call
77+
78+
hotpatch.reload();
79+
80+
and you'll have your updated library loaded into the app. Now, whenever you execute *getVersionString()* you will get *"libversion 2.0"*
81+
82+
## Compiling an application as a library (Android Studio / Eclipse):
83+
84+
1. Start a new android project
85+
2. Add the classes that you want to be updatable
86+
3. Build an APK
87+
4. Rename the .apk file to .jar
88+
89+
90+
## Changelog
91+
92+
- v1.0:
93+
- Support for methods
94+
- Implemented Hotpatch.loadLibrary()
95+
- Implemented Hotpatch.loadClass()
96+
- Implemented Hotpatch.loadMethods()
97+
- Implemented Hotpatch.reload()
98+
- Implemented Hotpatch.call()

0 commit comments

Comments
 (0)