Expand description
Generic Android JNI bindings for rustvncserver.
This crate compiles directly to a .so file that can be used by any Android app.
No wrapper crate needed - just configure your Java package at build time!
§Usage
Build with environment variables to configure your app’s Java package:
VNC_PACKAGE="com/mycompany/vnc" cargo ndk -t arm64-v8a build --releaseThen copy librustvncserver_android.so to your app’s jniLibs folder (rename as needed).
§Environment Variables
VNC_PACKAGE- Java package path (required), e.g.,"com/example/vnc"VNC_MAIN_SERVICE- Main service class name (default:"MainService")VNC_INPUT_SERVICE- Input service class name (default:"InputService")VNC_LOG_TAG- Android log tag (default:"RustVNC")
§Example Gradle Integration
def vncPackage = "com/mycompany/vnc"
environment "VNC_PACKAGE", vncPackage
environment "VNC_LOG_TAG", "MyApp-VNC"
commandLine 'cargo', 'ndk', '-t', 'arm64-v8a', 'build', '--release'§Java Side Requirements
Your Java classes need these native method declarations and callbacks:
public class MainService {
static { System.loadLibrary("droidvnc_ng"); } // or your lib name
// Native methods (registered at runtime via JNI_OnLoad)
public static native void vncInit();
public static native boolean vncStartServer(int w, int h, int port, String name, String pw, String httpDir);
public static native boolean vncStopServer();
public static native boolean vncIsActive();
public static native boolean vncUpdateFramebuffer(ByteBuffer buffer);
public static native boolean vncNewFramebuffer(int width, int height);
public static native long vncConnectRepeater(String host, int port, String id, String requestId);
// ... see full list in source
// Callbacks (called from Rust)
public static void onClientConnected(long clientId) { }
public static void onClientDisconnected(long clientId) { }
public static void notifyRfbMessageSent(String requestId, boolean success) { }
public static void notifyHandshakeComplete(String requestId, boolean success) { }
}
public class InputService {
public static void onKeyEvent(int down, long keysym, long clientId) { }
public static void onPointerEvent(int buttonMask, int x, int y, long clientId) { }
public static void onCutText(String text, long clientId) { }
}Functions§
- register_
vnc_ natives - Registers VNC native methods with the specified Java classes.