Skip to content

[GSOC] Fory Serialization Android Support #3405

@chaokunyang

Description

@chaokunyang

Feature Request

Add production-ready Android support for Fory Java serialization.

Is your feature request related to a problem? Please describe

Fory Java does not support Android well today. There are several limitations:

  1. Android reflection is very slow.
  2. JDK Unsafe APIs are unavailable or inconsistent across Android versions.
  3. JDK MethodHandle APIs are unavailable for many Android versions.
  4. Bytecode generated by Janino cannot run on Android.
  5. Generating source/bytecode on mobile devices is slow and resource-intensive.

Describe the solution you'd like

"Apache Fory Android support" should resolve the above limitations and prove production support for Fory serialization on Android:

  1. Use reflection only in very rare code paths.
  2. Add Android-specific Buffer and utility implementations guarded by a static final IS_ANDROID constant, and branch early in original hot paths.
  3. Do not use MethodHandle in Android execution paths.
  4. Do not generate bytecode at runtime; update java/fory-core/src/main/java/org/apache/fory/builder to generate stable source code that works across Android/JDK versions.
  5. Build an annotation processor that invokes java/fory-core/src/main/java/org/apache/fory/builder to generate target serializer code at build time.
  6. Hook generated serializers into the current type resolver so serialization uses generated code first.
  7. Verify Android support introduces no performance regression by running benchmarks/java and comparing results.
  8. Add CI coverage and comprehensive Android tests for functionality and compatibility.
  9. Update Fory Java guide docs and add a dedicated Android support document.

Describe alternatives you've considered

  1. Keep current Java runtime mechanisms (Unsafe, MethodHandle, Janino bytecode generation) and try partial Android compatibility. This is still fragile across Android versions.
  2. Use reflection-based serialization on Android as the default path. This likely causes unacceptable performance overhead.
  3. Maintain a separate Android-only serialization stack. This increases long-term maintenance cost and divergence.

Additional context

Expected outcomes:

  1. Android builds use compile-time generated serializers.
  2. Runtime compatibility is stable across major Android versions.
  3. Performance remains competitive with existing Java paths (no regressions on shared benchmarks).
  4. CI continuously validates Android support and prevents regressions.

Related issues:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions