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 compiles directly to a .so file that can be loaded by any Android app - no wrapper crate needed.
Key Features:
- Build-time configurable Java package via environment variables
- 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
1. Build the Library
# Set your Java package path
# Optional, defaults to "MainService"
# Optional, defaults to "InputService"
# Optional, defaults to "RustVNC"
# Build for Android
2. Copy to Your App
3. Add Java Native Methods
Environment Variables
| Variable | Required | Default | Description |
|---|---|---|---|
VNC_PACKAGE |
Yes | - | Java package path (e.g., com/mycompany/vnc) |
VNC_MAIN_SERVICE |
No | MainService |
Main service class name |
VNC_INPUT_SERVICE |
No | InputService |
Input service class name |
VNC_LOG_TAG |
No | RustVNC |
Android logcat tag |
Native Methods
Required Methods
These methods must be declared in your Java class:
| Method | Signature | Description |
|---|---|---|
vncInit |
()V |
Initialize the VNC runtime |
vncStartServer |
(IIILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)Z |
Start VNC server |
vncStopServer |
()Z |
Stop VNC server |
vncIsActive |
()Z |
Check if server is running |
vncConnectRepeater |
(Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;)J |
Connect to repeater |
Optional Methods
These methods are registered only if declared in your Java class:
| Method | Signature | Description |
|---|---|---|
vncUpdateFramebuffer |
(Ljava/nio/ByteBuffer;)Z |
Update framebuffer from ByteBuffer |
vncUpdateFramebufferAndSend |
(Ljava/nio/ByteBuffer;II)Z |
Update and send framebuffer |
vncUpdateFramebufferCropped |
(Ljava/nio/ByteBuffer;IIIIII)Z |
Update cropped region |
vncNewFramebuffer |
(II)Z |
Resize framebuffer |
vncSendCutText |
(Ljava/lang/String;)V |
Send clipboard text |
vncGetFramebufferWidth |
()I |
Get framebuffer width |
vncGetFramebufferHeight |
()I |
Get framebuffer height |
vncConnectReverse |
(Ljava/lang/String;I)J |
Connect to listening viewer |
vncGetRemoteHost |
(J)Ljava/lang/String; |
Get client's remote host |
vncGetDestinationPort |
(J)I |
Get client's destination port |
vncGetRepeaterId |
(J)Ljava/lang/String; |
Get client's repeater ID |
vncDisconnect |
(J)Z |
Disconnect specific client |
vncScheduleCopyRect |
(IIIIII)V |
Schedule CopyRect operation |
vncDoCopyRect |
(IIIIII)Z |
Execute CopyRect operation |
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 - Build-time configurable, production ready