Expand description
Turning a generated DEX into a live class.
The Apple backend synthesises a delegate with objc_allocateClassPair and
installs Rust functions with class_addMethod. Android’s equivalent is
three steps rather than two, because the class arrives as a file:
crate::dexemits a DEX defining the subclass, its overridesnative.InMemoryDexClassLoaderloads it — from aByteBufferover memory we own, so nothing is ever written to disk.RegisterNativesbinds eachnativemethod to a Rust function.
The result is a class Android cannot distinguish from a compiled one. It has a real superclass, a real constructor, and real methods; they simply happen to be implemented in Rust.
§Two things that will bite
InMemoryDexClassLoaderis API 26+. Below that the DEX has to reach a file, andDexClassLoaderneeds a writable optimised-output directory. There is no fallback here; the crate targets 26 and up.- The DEX bytes must outlive the loader.
NewDirectByteBufferdoes not copy, so the buffer is leaked deliberately — one allocation per class, for the life of the process.
Structs§
- Runtime
- The pieces of the Android runtime this crate needs, resolved once.
Enums§
- Error
- Why the runtime could not start.