That works great. It comes from cargo install cargo-ndk. It builds a .so library and I then use Android Studio to complete the app. But if I make the mistake of clicking Run or Build in IntelliJ (my Rust IDE) instead of Android Studio, then it does something to wipe the build results. Even if I kill it, if I then go back to cargo ndk …, the cargo command rebuilds everything.
It’s an annoyance. I wonder if there is a way, when I’m working on Android, to tell IntelliJ about this cargo ndk … command.
IntelliJ does see my .cargo/config.toml with the line:
target = "aarch64-linux-android"
And that causes IntelliJ to display sections marked #[cfg(target_os = “android”)] as active, which is nice, the build command still seems to be incompatible.
Rebuilds of everything are usually due to the value of the RUSTFLAGS environment variable changing. (Presumably cargo ndk sets it.) You can confirm this by adding the --verbose flag to the relevant cargo build command, and seeing what it tells you is “Dirty”. If this is the problem, you may be able to improve the situation by having IntelliJ set RUSTFLAGS to the same value.
Another possibility is to use separate target directories for the two builds, if you can afford the disk space.
Of course, it would be better to have IntelliJ run cargo ndk, but I don’t use IntelliJ and I can’t tell you how to do that.
If you open the Cargo Tool Window, then Run Cargo Command (one of the icons at the top looking like a crate), a popup Run anything will open. You can then type the arguments that come after the cargo command.
Another way to do that is Ctrl+Shift+A (Find Action) and type "run cargo command" or the first characters to launch the command from there.
You can also record a macro to launch that from a shortcut, but macros are a bit unreliable (for ex., if you have caps lock on, it'll likely type the command in uppercase). I'm using RustRover here, but that should be the same on IntelliJ Ultimate.
That will execute the command and put it in the run configurations. You can see it at the top (here it's named "ndk" because I typed ndk, even though I don't have the Android SDK).
run that configuration again (Shift+F10), but make sure "ndk" or the name you chose is selected!
save the configuration (which I did before taking the screenshot above) so that it remains in the list
Edit Configurations, once it's saved, to edit the parameters if you need to
Unfortunately, AFAIK, it's not possible to store that permanently nor to assign a direct shortcut to one of those run configurations. As you add run configurations, it may eventually drop your "ndk" configuration if it gets at the bottom of the list. I wish there was a better way, mostly to run the cargo check, which they forgot to add to the standard build commands.
Finally, I think you can also create a template from there so that creating a new run configuration for ndk is easier, but I've never used it (Run Configurations, then at the bottom left, Edit configuration templates...—or from the Find Action).