ClassBridge is a dynamic proxy library for Java and Android. It enables seamless interaction with hidden, dynamically loaded, or unavailable-at-compile-time classes using proxy mechanisms.
- Dynamic Class Loading: Loads classes at runtime using custom annotations.
- Proxy-Based Invocation: Enables method calls on classes that may not exist at compile time.
- Constructor Matching: Instantiates objects dynamically by resolving constructor parameters.
- Field & Method Access: Supports dynamic invocation of fields and methods, including
get_andset_conventions. - Supports Hidden/Internal APIs: Useful for interacting with restricted APIs (e.g., in Android frameworks).
- Easy Integration: Lightweight and dependency-free.
Download the latest JAR from GitHub Releases
Add it to your classpath.
Add it to libs folder and make sure your build.gradle has:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
}import dd.astolastudio.ClassBridge;
ClassBridge bridge = ClassBridge.Get();package com.package;
public class Test {
// Example of a static function
private static void doSomething(){
System.out.println();
}
}
@ClassName("com.package.Test")
public interface MyInterface {
@Static void doSomething();
}
MyInterface proxy = bridge.Static(MyInterface.class);
proxy.doSomething();Or non constant approach (dynamic):
MyInterface proxy = bridge.Static("com.package.Test", MyInterface.class);
proxy.doSomething();package com.package;
public class Test {
// Example of a constructor
private Test(String text){
// ...
}
protected void run(){
// ...
}
}
@ClassName("com.package.Test")
public interface MyInterface {
void run();
}
MyInterface instance = bridge.New(MyInterface.class, new Object[]{"param"});
instance.run();Or non constant approach (dynamic):
MyInterface instance = bridge.New("com.package.Test", MyInterface.class, new Object[]{"param"});
instance.run();package com.package;
public class Test {
// Example of a field
private String text;
private Test(String text){
this.text = text;
}
}
@ClassName("com.package.Test")
public interface MyInterface {
@Field String get_text();
@Field void set_text(String value);
}
MyInterface instance = ...
String value = proxy.get_text();
proxy.set_text("New Value");ClassLoader customLoader = new CustomClassLoader();
ClassBridge bridge = ClassBridge.Get(customLoader);ClassBridge relies on the following annotations:
Specifies the fully qualified name of the real class that should be proxied.
@ClassName("com.example.HiddenClass")
public interface HiddenAPI {}Or If you are lazy like me, the following corresponds to android.app.Application :
@ClassName("android.app.")
public interface Application {}And so does:
@ClassName("android.app.*")
public interface Application {}Marks a method as a static method when calling through a proxy.
@Static
void staticMethod();Used to identify that a method is a field (set/get) method when calling through a proxy.
@Field Object get_field();
@Field void set_field(Object value);There are some code examples you can find Here. There are many usecases, but i am too lazy to write them all in here. It wouldn't even be fun, if i tell you everything. You'll love it more, if you try it yourself. You'll learn more, find more.
| Platform | Minimum Version |
|---|---|
| Java | 7+ |
| Android | API 1+ |
ClassBridge is licensed under the MIT License.
Contributions are welcome! To contribute:
- Fork the repository.
- Create a new branch (
feature-branch). - Commit your changes.
- Open a Pull Request.
For any questions or feature requests, open an issue or contact me at astolastudio@gmail.com.