I have a Rust application I compile for android using cargo apk build . I would like to arrange for the AndroidManifest.xml to include
<uses-permission
android:name="com.oculus.feature.PASSTHROUGH"
android:required="true"
/>
but all my attempts have failed.
Stackoverflow's AI suggests using
[package.metadata.android] permissions = [ "com.oculus.feature.PASSTHROUGH" ]
in my Cargo.toml, but that does not succeed. I have also tried
[[package.metadata.android.uses-permission]]
name = "com.oculus.feature.PASSTHROUGH"
required = "false"
and
[[package.metadata.android.uses-permission]]
"android:name" = "com.oculus.feature.PASSTHROUGH"
required = "false"
(that last one was based on modifying the cargo-apk source to derive serde::Serialize and outputting a modified manifest to see what it looked like)
None of the examples that come with the cargo-apk show how to declare permissions.
There is clearly a
#[serde(rename(serialize = "uses-permission"))]
#[serde(default)]
pub uses_permission: Vec<Permission>,
field in the AndroidManifest struct of ndk-build . What is the proper technique to populate it so that my application can have access to the features I want?
After poking around a little more I discovered <https://github.com/rust-mobile/cargo-apk/tree/main/cargo-apk#manifest> which says I should be using
[[package.metadata.android.uses_permission]]
name = "com.oculus.feature.PASSTHROUGH"
required = "false"
The most alarming part of this solution is that it is what I had in my Cargo.toml at the start of the adventure. Why it did not result in the clauses appearing in AndroidManifest.xml before today is a mystery.
Getting the user to approve the permissions at run-time is its own bucket of spiders: https://stackoverflow.com/questions/76671942/how-can-a-rust-application-on-android-request-permissions-like-read-external-sto
Mutant Bob