Skip to content

Sharing physics code between Desktop and Android — recommended / supported approach? #196

@bolotov

Description

@bolotov

Summary / Problem

When targeting both Desktop and Android, it is currently easy to accidentally structure a project in a way that causes desktop physics code or bytecode to be pulled into Android builds, leading to runtime failures on Android.

In particular, placing physics setup code (e.g. creating PhysicsWorld, Material, RigidDynamic, etc.) into a shared JVM or KMP module can result in the shared code being compiled against the desktop JVM variant of kool-physics. This embeds desktop-specific bytecode into the shared module, which then fails to load on Android at runtime.

From a user perspective, this is not obvious and can happen naturally when trying to reduce duplication and share scene/physics logic.


Observations

  • Kool provides separate Desktop and Android physics artifacts with the same public API but different compiled bytecode.
  • A shared JVM module must resolve one concrete variant at compile time, which defaults to the desktop one .
  • As a result, shared physics code may unintentionally depend on desktop-only classes, even if Android dependencies are declared correctly.
  • Kool examples seem to avoid this implicitly by keeping physics construction platform-specific or desktop-only, but this constraint is not explicitly documented.

Question / Request for guidance

What is the intended or recommended way to structure physics code when supporting both Desktop and Android?

In particular:

  • What is the best way to share physics code, android / desktop sharing.
  • Are there supported or preferred patterns for sharing physics-related logic safely (e.g. facades, backends, expect/actual, etc.)?
  • Minimal docs...

Even brief guidance on how you envision this being handled would help avoid accidental misconfiguration and runtime issues.


Thanks for your work on Kool and for any advice you can provide.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions