Skip to content

feat: Add Android platform release targets with integrated JNI support #1145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

n8fr8
Copy link

@n8fr8 n8fr8 commented Jun 3, 2025

Changes in this pull request

This PR integrates support for building the C API library targeting Android ARM64 and X86_64 with the local Makefile build process.

It also integrates the RUST-JNI crate to provide a first pass of an integrated Java Native Interface (JNI) which, unlike with Swift iOS, is required for calling into the library from Kotlin or Java in the Android environment. This interface will be improved in future PRs to be more in platform style.

The Makefile changes also integrate support for installing the required Android Native Development Kit (NDK) tools for completing the build.

Checklist

  • This PR represents a single feature, fix, or change.
  • All applicable changes have been documented.
  • Any TO DO items (or similar) have been entered as GitHub issues and the link to that issue has been included in a comment.

@gpeacock
Copy link
Collaborator

gpeacock commented Jun 5, 2025

Is there a reason why this needs to be done in the library instead of in external JNI connected to the C bindings?

Copy link
Collaborator

@scouten-adobe scouten-adobe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks OK to me with the caveat that I'd like review on some JNI specifics.

@scouten-adobe scouten-adobe changed the title Add Android platform release targets with integrated JNI support feat: Add Android platform release targets with integrated JNI support Jun 5, 2025
@@ -0,0 +1,477 @@
// Copyright 2024 Adobe. All rights reserved.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we move this out, even to its own folder (crate)? Because since it's JNI, this could maybe be reused in the future for Java bindings which are not specific to Android (or refactored to share some code with that, if we ever have a Java SDK)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An other argument to move this out is to add tests (unit tests, on this file), but also some Java tests. Especially to verify the stream behavior when we cross languages.
@gpeacock @n8fr8 Wdyt?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to put it where you think it is best. I do not believe there is anything Android specific here that wouldn't also work in a generica Java/Kotlin environment.


/// Returns a ManifestStore JSON string from a file path
#[no_mangle]
pub extern "system" fn Java_org_c2pa_C2PA_readFile(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack - but we should consider using readers to do that, as they are an important piece of the API surface (and it reduces the exposed API surface too, so people use the API's main concepts).


/// Creates and verifies a C2paReader from an asset stream with the given format
#[no_mangle]
pub extern "system" fn Java_org_c2pa_C2PA_readerFromStream(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we have the reader - that is similar in spirit to Java_org_c2pa_C2PA_readFile, if we open the file as stream and pass it to a Reader, to finally get the manifest store as JSON.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are still fully getting our heads around the best practices of the 2.x API ourselves. Readers do make sense, and again, will be more inline with the Android/Kotlin/Java idiom than just raw JSON.

Also, we do plan to continue to have a "SimpleC2PA" library as well, on top of the "Full API", that even further simplifies integration for the most common and basic functions in a mobile app.

@n8fr8
Copy link
Author

n8fr8 commented Jun 11, 2025

I will work on resolving the Makefile conflict this week. I believe that relates to the recent work of @redaranj that was merged.

@tmathern tmathern self-requested a review June 12, 2025 02:35
@tmathern
Copy link
Contributor

Regarding the failures: cargo +nightly fmt --all -- --check will suggest you Rust formating & good practices if you run it before merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants