rustvncserver-android
Generic Android JNI bindings for rustvncserver - a pure Rust VNC server library.
Support this project:
Overview
This crate provides ready-to-use Android JNI bindings for the rustvncserver library. It uses runtime configuration via Java system properties - just set properties before loading the library and everything is configured automatically.
Key Features:
- Runtime configurable Java package via system properties (no build-time config needed)
- Use as a crates.io dependency - no custom JNI code required
- Flexible JNI method registration (required vs optional methods)
- Full VNC server lifecycle management
- TurboJPEG support for hardware-accelerated JPEG compression
- Works with any Android app package structure
Quick Start
Option 1: As a Dependency (Recommended)
Add to your Cargo.toml:
[]
= "my-vnc-app"
= "2021"
[]
= ["cdylib"]
[]
= { = "1.0", = ["turbojpeg"] }
Create a minimal src/lib.rs:
// Re-export everything including JNI_OnLoad
pub use *;
In your Java code, set system properties BEFORE loading the library:
Option 2: Manual Registration
If you need more control, skip the system properties and call register_vnc_natives() from your own JNI_OnLoad:
use register_vnc_natives;
use JavaVM;
use ;
use c_void;
pub extern "system"
System Properties
Set these properties in Java before calling System.loadLibrary():
| Property | Required | Default | Description |
|---|---|---|---|
rustvnc.main_service_class |
Yes | - | Full class path (e.g., com/mycompany/vnc/MainService) |
rustvnc.input_service_class |
Yes | - | Full class path (e.g., com/mycompany/vnc/InputService) |
rustvnc.log_tag |
No | RustVNC |
Android logcat tag |
Native Methods
Required Methods
These methods must be declared in your Java class:
// Start VNC server with given dimensions, port, name, password, and HTTP root dir
private native boolean ;
// Stop the VNC server
private native boolean ;
// Check if the server is currently running
private native boolean ;
// Connect to a UltraVNC repeater
private native long ;
Optional Methods
These methods are registered only if declared in your Java class:
// Framebuffer updates
static native boolean ;
static native boolean ;
static native boolean ;
static native boolean ;
// Framebuffer info
static native int ;
static native int ;
// Clipboard
static native void ;
// Connections
static native long ;
// Client info (pass clientId from callbacks)
static native String ;
static native int ;
static native String ;
static native boolean ;
// CopyRect optimization (for scrolling/window dragging)
static native void ;
static native boolean ;
Callbacks
The library calls these static methods on your Java classes:
MainService Callbacks
public static void
public static void
public static void
public static void
InputService Callbacks
public static void
public static void
public static void
Gradle Integration
Example build.gradle task for building the Rust library:
tasks.
tasks.whenTaskAdded
Features
| Feature | Description |
|---|---|
turbojpeg |
Enable TurboJPEG for hardware-accelerated JPEG compression |
debug-logging |
Enable verbose debug logging |
TurboJPEG Setup
For turbojpeg support, you need to build libjpeg-turbo for Android. See the libjpeg-turbo Android build guide for details.
Platform Support
- Android arm64-v8a (primary target)
- Android armeabi-v7a
- Android x86_64
- Android x86
Dependencies
This crate depends on:
- rustvncserver - Pure Rust VNC server library
- jni - Rust JNI bindings
- tokio - Async runtime
- android_logger - Android logcat integration
License
Apache-2.0 - See LICENSE file for details.
Credits
- Author: Dustin McAfee
- VNC Server: rustvncserver
- Encodings: rfb-encodings
See Also
- rustvncserver - The underlying VNC server library
- RustVNC - Example Android VNC server app using this library
- RFC 6143 - RFB Protocol Specification
Android JNI bindings for rustvncserver - Runtime configurable, production ready