-
Notifications
You must be signed in to change notification settings - Fork 110
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
Cant compile the ndk-context example from the documentation #364
Comments
The example uses |
@rib changed this for you: jni-rs/jni-rs@425a886#diff-51083e4297cac9f54fc9c9d4e15f62a2ab016f341edcf776b2172a7ec444e7cc Either downgrade to |
? the jni-rs 0.20 API had some breaking changes (as reflected in the semver bump) to help address some soundness / safety issues - it's not nice having someone just point and blame you personally like this :/
huh, this needs re-wording I think; you're apparently calling @charleschege incompetent!? please keep feedback technical and not personal! |
@charleschege to compile against jni-rs 0.20 that snippet in particular can be updated like: // Create a VM for executing Java calls
let ctx = ndk_context::android_context();
let vm = unsafe { jni::JavaVM::from_raw(ctx.vm().cast()) }?;
let context = unsafe { JObject::from_raw(ctx.context().cast()) }; // <-- can get JObject for a raw pointer like this
let env = vm.attach_current_thread()?;
// Query the global Audio Service
let class_ctxt = env.find_class("android/content/Context")?;
let audio_service = env.get_static_field(class_ctxt, "AUDIO_SERVICE", "Ljava/lang/String;")?;
let audio_manager = env
.call_method(
context,
"getSystemService",
// JNI type signature needs to be derived from the Java API
// (ArgTys)ResultTy
"(Ljava/lang/String;)Ljava/lang/Object;",
&[audio_service],
)?
.l()?; |
So it's different from "I have tried compiling the example in the docs", as the user is compiling an unchanged variation of the example against a semver-incompatible version of
The bit you quoted was already reworded well before you replied?
Why are you insinuating this!?
This isn't feedback, it's unpaid support on a deteriorating opensource ecosystem. @rib I'd greatly appreciate it if you can PR the upgrade to |
Sorry to hear that, I thought traverse research was funding your work
Wouldn't say deteriorating. We have a brand new glue layer meaning that the |
just fyi without @rib saving my ass with his awesome android work I'd have been in real trouble using any of the rust android ecosystem. it's quite easy to write an activity in kotlin and call it from the native activity now. |
okey, right I see that this probably wasn't what you intended, thanks for re-wording it.
Perhaps I read into it too much - with the structure of the sentence it's possible to see an implication here, even though I take it that's not what you intended.
I'm sorry you feel this way. I had started making a patch for jni 0.20 yep and can hopefully make a PR in a bit. I'm afraid I don't know what your last comment about ignored PRs is referring to but sorry if that's directed at me and there's some PR you want me to look at? |
yeah incidentally I've recently been pondering having some kind of "Android Gems" org to be able to collate modular JNI libraries that may go beyond what the ndk supports (e.g. thinking of libraries for things like permission requests) and maybe it could be beneficial to house more of the build system projects in the same place if it helps with discovery. On the other hand I suppose I'm not always convinced that bundling all closely related projects under Github Organisations is the best way to go if it starts to look more like a walled garden than an open community. The idea of modularising the android-ndk repo does sound like it would be good and then putting the split out repos under a more general android org instead of There are also projects like mozilla's gradle / cargo plugin (I forget the name) and the crosstool project which also looks like it's trying to tackle similar things to xbuild. I have a rust bluetooth library with android support which could potentially make sense there - though that's also designed to support other platforms too so maybe not. but yeah getting off-topic I guess |
it would be a real shame if such a library didn't support ios/desktop. it could be part of this org, but in that case it would be more along the lines of platform support instead of purely android. I guess that could be a reason why
well, the question is do you really want to keep maintaining cargo-apk. I wrote the initial version of cargo-apk and ndk-build, but no longer think that it's the best path forward. and redesigning a tool for each platform doesn't make much sense imo. especially for more esoteric use cases. so moving xbuild into the same org is more about committing to stop maintaining cargo-apk and update docs etc to use xbuild.
can you point me to the crosstool project? there isn't a crate called crosstool on crates.io. I think xbuild is pretty unique in that it's the only project that supports developing ios apps on linux. other projects all just use |
Yeah it's a likely way in which the idea of organising things by "android" might not end up being the most desirable line to draw. Similar to having a utility library for permissions, you could imagine that for all kinds of other utilities there would also be interest in having cross-platform libraries too. This https://github.com/amodm/webbrowser-rs seems like a good illustrative example too. That said though it's not unreasonable to expect that those portable abstractions would often make sense to build on top of other platform-specific crates. Portable abstractions inherently make trade offs when they generalize across platforms and there will usually be many different portable frameworks over time that may make different choices / trade offs. The platform-specific libraries would be more focused on exposing the capabilities of one platform - E.g. considering that Android's permission model is not exactly the same as on iOS.
Yeah I have no strong opinions here I suppose. If others want to keep on developing Conceptually a tool like xbuild that can cover more use cases than I would guess they could live side by side in an organisation with different maintainers and top-level docs could explain the trade offs the help people determine which tool is appropriate for their use case. If
Ah sorry I got the name wrong; it's "crossbow" my bad; I think I heard the project name in passing recently and then it came up again when discussing Android support for Bevy the other day here: bevyengine/bevy#86 Anyhow lets carry on this discussion here: #365 |
We are actively using all crates under
It is becoming more and more divergent with everyone spawning their own project to solve a new problem rather than attempting to improve/refactor the status quo. rust-windowing isn't the right place, but as you mentioned we do need a cohesive place (i.e. an organization) to keep everything Rust+Android in one place: both to communicate to users what the current "Way of doing things" is, and to keep everyone working on Rust+Android support in sync. Maybe I've just grown too attached to Same for I'd have to check again where we stand now after a few things have been merged: for example
Thanks, looking forward to that.
The current approach makes me feel lost in a wasteland, to stick with the chosen terminology.
Totally on-board with this. OTOH it may not perfectly align with e.g.
There are a few more, afaik.
I'd prefer to not maintain multiple with a 99% overlap in feature-set, but as detailed right above Indeed, let's move to #365 as we're well beyond derailing this thread 😏 |
Thank you all for taking the time to respond to my query. I am new to using JNI bindings on Android so I just opened the docs, copied the first example I saw and tried to compile that. I also agree that having an android org for common libraries as an easy way to find them. I am only able to try out new things after work hours so having a github org or website that I can quickly lookup whether a library exists or not would be a great option. Thanks again |
FYI some of what might have made xbuild hard to follow is that it had various contortions to build flutter applications. All that code has been removed recently (2500loc). If you still think there is something difficult to understand or convoluted you can point me to it. One thing that may not be great is when cobbling together various proprietary file formats with little to no documentation. On android the situation is such that there is code for the arsc format in ASOP so it's not as terrible as it could have been. And all this extra complexity comes from trying to avoid external tools and dependencies. so we imement apk signing in rust instead of using |
I have tried compiling the example in the docs
I get the error
Where could I be wrong ?
The text was updated successfully, but these errors were encountered: