Skip to content

Rust with Native Android / iOS #208

Description

@dougg0k

Hey,

Is there a way to get ferric-cli / napi working with Android / iOS?

Activity

  1. shirakaba commented on Jul 28, 2025

    @shirakaba
    Collaborator

    I wrote a walkthrough, Build and Run Node-API Modules in React Native, which shows how to create a Node-API module to run on Node.js, Android, and iOS.

    I am not familiar with the Ferric side of things, but hopefully that fills in some of the gaps.

  2. dougg0k commented on Jul 28, 2025

    @dougg0k
    ContributorAuthor

    I didnt check, though It might be possible by importing the .so file in android and the respective on ios.

    I suppose having it added in the init or readme, would bring some clarity.

  3. kraenhansen commented on Jul 29, 2025

    @kraenhansen
    Collaborator

    I don't fully understand your request.

    Are you asking for ways to load the prebuilds outside of the context of React Native?

  4. dougg0k commented on Jul 29, 2025

    @dougg0k
    ContributorAuthor

    No, in the context. But also in the native side.

  5. kraenhansen commented on Jul 29, 2025

    @kraenhansen
    Collaborator

    Please elaborate more on your question, provide an example or add some other context. Ferric is meant to produce prebuilds for Android and iOS out of the box.

    What do you mean by, "in case something is needed from it?"

  6. dougg0k commented on Jul 29, 2025

    @dougg0k
    ContributorAuthor

    That was badly written. Fixed.

  7. kraenhansen commented on Jul 29, 2025

    @kraenhansen
    Collaborator

    I suspect this is mostly a case of missing examples and documentation. In its current form, loading the prebuild requires three things:

    • The prebuild conforms with the format specified in docs/PREBUILDS.md.
    • The app needs to configure Babel to use the Babel plugin (this requirement might be lifted when authoring libraries and not using existing packages with Node-API addons intended for Node.js):
      plugins: ["module:react-native-node-api/babel-plugin"],
    • The app needs to require the addon (the test app does this here which in turn defers to the main field of the ferric-example package here which does a require of the addon prebuild from the generated ferric_example.js.
  8. dougg0k commented on Jul 29, 2025

    @dougg0k
    ContributorAuthor

    That seem to be steps for JS though, not actually use the rust native API in the android/ios side.

    Rust > Android > JS > Android > Rust
    Rust > iOS > JS > iOS > Rust
    

    this is somewhat what I previously meant, in case, it was needed.

  9. kraenhansen commented on Jul 30, 2025

    @kraenhansen
    Collaborator

    Sorry 😔 I'm still not getting this. I'm genuinely curious, but I can't wrap my head around it.

    Do you want to call into platform-specific native APIs (such as the Android SDK) from your Rust library code? Or do you want to load or call into your Node-API addon from native code (Java, Kotlin, Objective-C or Swift) - if yes for what purpose?

    Can you speak a bit about the use-case? What are you trying to achieve here?

  10. dougg0k commented on Jul 30, 2025

    @dougg0k
    ContributorAuthor

    None at the moment, but I had some thoughts on building a library which could make use of this. But still not sure I will go forward with it. Some APIs from android or ios, might not be available on rust, so, some impl could end up needing a mix up.

  11. dougg0k commented on Jul 30, 2025

    @dougg0k
    ContributorAuthor

    I checked some information.

    If the output supported multiple ABIs targets.

    For android, in the most succinct way, would be something like.

    rust_lib > dist > arm64-v8a > rust_lib.so
                      armabi-v7a > rust_lib.so
    etc...
    

    In build.gradle at android/app, add

    android {
        ...
        sourceSets {
           main {
                jniLibs.srcDirs = ["${rootDir}/rust_lib/dist"]
           }
        }
    }
    

    For ios, not entirely sure yet, but likely to be with the .podspec or Podfile.

    s.vendored_frameworks = '../../rust_lib/dist/rust_lib.xcframework'
    
    pod 'RustLib', :path => '../../rust_lib/dist/rust_lib.xcframework'
    

    I suppose there is no real way to automate without specifying the settings.

  12. kraenhansen commented on Jul 30, 2025

    @kraenhansen
    Collaborator

    Can't really comment meaningfully before I understand what you're trying to achieve.

    But it does seem like you are painting the picture of what our host package is already doing while auto-linking.

  13. locked and limited conversation to collaborators on Jul 30, 2025
  14. converted this issue into a discussion #212 on Jul 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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