Closed MarijnS95 closed 9 months ago
Besides,
ndk-glue
has been deprecated for some time and should be replaced byandroid-activity
in the example in a followup PR.
In hindsight, while looking into this project, it seems to rely on some complicated interplay between Android's NativeActivity
class that _automatically loads the library specified via android.app.lib_name
meta-data
and calls into its entrypoint provided via ndk-glue
or android-activity
_, and again manually loading the library via System.loadLibrary
in order to invoke JNI_OnLoad
. That needs some more clarification and cleanup.
In fact:
winit
;Bridge
class could be a very simple single .class
file (afaik) that is pre-bundled with this crate;cargo-apk
/xbuild
) without any extra Java setup, gradle
nor Android Studio;Awesome, if you can pull all that off, I'd be very appreciative. I'd love to see Android support improved but I'm so far behind on maintaining this project that it hasn't been a priority.
FWIW I've made attempts at this in the past and gave up partway along the way, but if you can improve it and verify that it works, that'd be great. I'd love to try mobile game development with TTS support on Android.
Sounds good; perhaps we can already get this PR in and I'll think about taking a look.
In my mind there are essentially two ways to develop Android apps with Rust:
NativeActivity
to load a shared object with C symbols (provided by ndk-glue
/android-activity
), which contains a full activity lifecycle and the right APIs to render to the screen, handle input events, and a few releated actions (see the Android NDK: https://developer.android.com/ndk and https://github.com/rust-mobile/ndk). Android's NativeActivity
marshals some of these lifecycle events back and forth over an FFI boundary. No Java/Kotlin code is compiled/needed;
GameActivity
, which behaves much like NativeActivity
but has a Java/C++ support layer (that needs to be compiled and bundled) to provide more (and more consistent) functionality to a native implementation;This example app, from what I understand, appears to try both. I think we'd address the elephant in the room by moving to an explicit .with_android_app()
constructor like winit
, instead of having a JN_OnLoad
behind the users' back.
That'd clean up the support for purely native apps with a minimal example, if we figure out how to cleanly embed the Bridge
class.
Likewise, for non-android-activity
apps there are different means to pass the JavaVM
to tts-rs
, and we can keep + simplify the Android-Studi/gradle-based app.
For now I'm not even sure how the example app is intended to be built, since a hello_world
library is referenced twice (in android.app.lib_name
meta-data
_and in System.loadLibrary()
), while app/gradle.build
requests the tts
crate to be built as cdylib
?
@ndarilek is this something you might still want to merge? I won't have any time in the coming months to look into improving Android support for this project, but the PR/fix is valid as proposed and solves a real "issue" out in the wild.
We can always reference one of these replies in a new issue to keep track of ideas for future improvements.
Commit d42d201 ("Update Android dependencies and example.") correctly replaces
ndk-glue
withndk-context
as a more generic crate to hold on to a globalJavaVM
and Androidjobject
Context
, but didn't drop the unusedndk-glue
crate from the list of Android dependencies. This crate is only used in the example crate, and shouldn't clobber downstream crates.Besides,
ndk-glue
has been deprecated for some time and should be replaced byandroid-activity
in the example in a followup PR.