diff --git a/.changeset/strong-cycles-spark.md b/.changeset/strong-cycles-spark.md new file mode 100644 index 00000000..c0394702 --- /dev/null +++ b/.changeset/strong-cycles-spark.md @@ -0,0 +1,5 @@ +--- +'@use-voltra/android-client': patch +--- + +Fix Android builds for React Native 0.81 apps by linking the correct Hermes prefab target. diff --git a/packages/android-client/android/CMakeLists.txt b/packages/android-client/android/CMakeLists.txt index 1cddb02b..1ab72058 100644 --- a/packages/android-client/android/CMakeLists.txt +++ b/packages/android-client/android/CMakeLists.txt @@ -8,12 +8,25 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) # We consume them through find_package below. # # NOTE: find_package does NOT error on a wrong target *name* — the failure only -# surfaces at target_link_libraries. The correct Hermes prefab target on Android -# (RN 0.83, com.facebook.react:hermes-android) is `hermes-engine::hermesvm`. +# surfaces at target_link_libraries. The Hermes prefab target on Android has +# been renamed across RN versions (com.facebook.react:hermes-android): +# - RN <= 0.81: prefab module `libhermes` -> CMake target hermes-engine::libhermes +# - RN >= 0.82: prefab module `hermesvm` -> CMake target hermes-engine::hermesvm +# We branch on which target find_package actually resolved so Voltra builds +# against both RN generations, and fail fast at configure time if neither +# exists (e.g. a future prefab rename) instead of erroring later at link time. find_package(ReactAndroid REQUIRED CONFIG) find_package(hermes-engine REQUIRED CONFIG) find_package(fbjni REQUIRED CONFIG) +if(TARGET hermes-engine::hermesvm) + set(VOLTRA_HERMES_TARGET hermes-engine::hermesvm) # RN >= 0.82 +elseif(TARGET hermes-engine::libhermes) + set(VOLTRA_HERMES_TARGET hermes-engine::libhermes) # RN <= 0.81 +else() + message(FATAL_ERROR "Voltra: hermes-engine prefab found but neither target hermes-engine::hermesvm (RN >= 0.82) nor hermes-engine::libhermes (RN <= 0.81) exists. Unsupported React Native version?") +endif() + # --------------------------------------------------------------------------- # Voltra JS Renderer (Dynamic Widgets on Android) # --------------------------------------------------------------------------- @@ -28,6 +41,13 @@ target_link_libraries(voltra_js_renderer android log ReactAndroid::jsi - hermes-engine::hermesvm + ${VOLTRA_HERMES_TARGET} fbjni::fbjni ) + +# 16KB page size support: explicitly align libvoltra_js_renderer.so to 16KB +# pages regardless of host NDK version. NDK r28+ defaults to this, but we +# pin it explicitly so older NDKs also produce 16KB-compatible output. We +# only support 16KB alignment (no 4KB-only build) — 16KB-aligned libs run +# fine on 4KB-page devices too. +target_link_options(voltra_js_renderer PRIVATE "-Wl,-z,max-page-size=16384") diff --git a/packages/android-client/android/build.gradle b/packages/android-client/android/build.gradle index a2b61838..cd12cdc0 100644 --- a/packages/android-client/android/build.gradle +++ b/packages/android-client/android/build.gradle @@ -59,7 +59,7 @@ android { buildFeatures { buildConfig true compose true - // Required to consume React Native's published prefab modules (jsi, hermesvm, fbjni). + // Required to consume React Native's published prefab modules (jsi, hermes, fbjni). prefab true } @@ -71,6 +71,7 @@ android { "**/libfbjni.so", "**/libjsi.so", "**/libhermes.so", + "**/libhermesvm.so", ] } @@ -95,10 +96,11 @@ android { dependencies { // React Native implementation "com.facebook.react:react-android" - // Provides the `hermes-engine` prefab (libhermesvm) that CMakeLists.txt's - // find_package(hermes-engine) consumes for the standalone Hermes JS runtime. Without it the - // native build fails to configure in release variants (react-android alone does not publish the - // Hermes prefab). Version is substituted by the React Native Gradle Plugin (applied above). + // Provides the `hermes-engine` prefab (libhermes on RN <= 0.81, libhermesvm on RN >= 0.82) + // that CMakeLists.txt's find_package(hermes-engine) consumes for the standalone Hermes JS + // runtime. Without it the native build fails to configure in release variants (react-android + // alone does not publish the Hermes prefab). Version is substituted by the React Native + // Gradle Plugin (applied above). implementation "com.facebook.react:hermes-android" // Jetpack Glance