Skip to content

Commit cf9625e

Browse files
Updated README.md
1 parent f628f92 commit cf9625e

File tree

1 file changed

+68
-16
lines changed

1 file changed

+68
-16
lines changed

README.md

Lines changed: 68 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,83 @@
22
[![Github All Releases](https://img.shields.io/github/downloads/charslab/Android-Hotpatch/total.svg)](https://github.com/charslab/Android-Hotpatch/releases)
33
[![license](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/charslab/Android-Hotpatch/blob/master/LICENSE)
44

5-
Autopdate an android app on the fly
5+
Update or fix an android app on the fly, without having to publish a new APK.
6+
67

78
## Usage:
89

9-
## Example:
10+
1. Make a .jar library with your app's classes and methods that you want to be updatable (see #compiling a library)
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+
20+
21+
## Quick usage demo:
22+
23+
Let's say we have a class that we want to use in our Android app, defined this way:
1024

25+
```JAVA
26+
package com.chars.testlib.TestLib;
27+
28+
public class TestLib {
29+
public String getVersionString() {
30+
return "libversion 1.0";
31+
}
32+
}
33+
```
34+
35+
After making a .jar library of that class, deploy it to you device i.e in */sdcard/TestLib.jar*
36+
37+
In order to use it in your Android app, you must load it with Hotpatch
1138

1239
```JAVA
13-
final String className = "com.chars.testlib.TestLib";
14-
final String methods[] = {"getVersionString"};
40+
final String className = "com.chars.testlib.TestLib";
41+
final String methods[] = {"getVersionString"};
42+
43+
final Hotpatch hotpatch = new Hotpatch();
1544

16-
final Hotpatch hotpatch = new Hotpatch();
45+
try {
46+
hotpatch.loadLibrary("/sdcard/TestLib.jar", getApplicationContext());
47+
hotpatch.loadClass(className);
48+
hotpatch.loadMethods(className, methods);
49+
50+
String result = (String)hotpatch.call(className, methods[0]);
51+
Log.d("AndroidHotpatch", result);
52+
53+
} catch (Exception e) {
54+
Log.e("AndroidHotpatch", Log.getStackTraceString(e));
55+
}
56+
```
57+
58+
The line
59+
60+
String result = (String)hotpatch.call(className, methods[0]);
1761

18-
try {
19-
hotpatch.loadLibrary("/sdcard/TestLib.jar", getApplicationContext());
20-
hotpatch.loadClass(className);
21-
hotpatch.loadMethods(className, methods);
22-
23-
String result = (String)hotpatch.call(className, methods[0]);
24-
Log.d("AndroidHotpatch", result);
25-
26-
} catch (Exception e) {
27-
Log.e("AndroidHotpatch", Log.getStackTraceString(e));
28-
}
62+
will execute the *getVersionString()* method, defined in class *TestLib*.
63+
64+
To update the library, just make a new .jar from an updated version of the class. For example:
65+
66+
```JAVA
67+
package com.chars.testlib.TestLib;
68+
69+
public class TestLib {
70+
public String getVersionString() {
71+
return "libversion 2.0";
72+
}
73+
}
2974
```
75+
Push the updated .jar to the same path as the previous. In your Android app, you can just call
76+
77+
hotpatch.reload();
78+
79+
and you'll have your updated library loaded into the app. Now, whenever you execute *getVersionString()* you will get *"libversion 2.0"*
80+
81+
## Compiling an application as a library:
3082

3183

3284

0 commit comments

Comments
 (0)