BrainiumLLC / cargo-mobile

Rust on mobile made easy!
Apache License 2.0
1.21k stars 52 forks source link

Questions regarding this crate #23

Open Joe23232 opened 3 years ago

Joe23232 commented 3 years ago

Hi I have some questions regarding this crate:

  1. Am I able to make full blown Android applications by using this crate and the fltk-rs GUI library crate?
  2. Is it stable or beta/alpha?
  3. Is there a docs page that is similar to the Rust Programming Book?
  4. Is it more difficult to use or easier to use compared to using Android Studio Java?
  5. Am I required to use Android Studio for this? If so then am I required to do some Java programming as well?
  6. If I wanted to do something that is specific to Android, for example list out all the apps installed or to create a lockscreen for the user (this wouldn't work on iOS nor Linux), then would this crate still work? Am I able to call Android APIs in a high level manner just like with Android Studio Java?
francesca64 commented 3 years ago

Thanks for asking!

  1. If fltk-rs supports Android, then yes. cargo-mobile is mostly just a build tool, so it ideally won't be a limiting factor. However, depending on what "full blown" means to you, you might need to fine-tune the generated gradle/manifest/etc. files in ways that we don't currently automate. We're always looking to improve cargo-mobile's flexibility, so if you find yourself in that situation, feel free to open an issue or a PR!
  2. None of the above, honestly. It's intended to be useful right now, since if it weren't, I wouldn't have released it! However, the design and behavior are subject to change in potentially breaking ways if we feel that doing so would make cargo-mobile more useful for more people. If that happens, it'll be clearly communicated in a CHANGELOG and in an update announcement. We use cargo-mobile internally at Brainium, so I'm able to guarantee a certain level of support and refinement into the future.
  3. There isn't currently one, sorry. I'd love to have more extensive and empowering documentation, but that simply wasn't a priority for the initial release. The announcement blog post, README, and template projects ideally cover the lowest-common denominator of usage, though.
  4. Making an Android app the traditional way using Java/Kotlin and the official tooling and surrounding ecosystem will hands-down 100% be easier for the vast majority of apps. Even if you're making something where you need more control over rendering and performance, like a game, you'd have a much easier time using C++ and just following along with NDK guides, or using established higher-level frameworks and tools. The only reason to write your app in Rust is out of passion, and the conviction that it'll lead to long-term gains.
  5. I recommend having Android Studio installed, since it makes it easy to install the SDK and NDK, among other things. However, you can use cargo-mobile without ever needing to open Android Studio by using commands like cargo android build and cargo android run. You aren't required to use Java at all, though you'll absolutely need to interface with various NDK and JNI APIs if you wish to build a full-blown app. How you do that is ultimately up to you, since cargo-mobile is only responsible for your build process, not your app internals. All of the template packs we currently have use android-ndk-rs's ndk-glue under the hood to give you access to your NativeActivity and all sorts of other things, so consulting the docs over there is your best bet for learning how to do that in pure Rust. If you find it more convenient to use Java directly for some parts of your app, that's discussed a bit in #17.
  6. cargo-mobile is only a build tool, so the way you'd do that is the same as you'd do it in any other Rust program. Conditional compilation and android-ndk-rs are your friends for that! Likewise, cargo-mobile doesn't give you any higher-level access to those APIs than you get using android-ndk-rs, since well, you're still directly using android-ndk-rs. If you're looking for the ergonomics and productivity provided by using Java/Kotlin to build apps using official tooling, then I highly recommend you use Java/Kotlin to build apps using official tooling.
Joe23232 commented 3 years ago

@francesca64 I see mate, thanks for your response :)

The difference in a nutshell is that cargo-apk is a cool standalone tool for building your Rust project as an APK, whereas cargo-mobile is designed to integrate with Android Studio and Xcode. They both give you an APK in the end, but follow two different equally-valid approaches to getting there.

So I suppose cargo-apk is something I wish to proceed with then. I suppose this is a crate?

francesca64 commented 3 years ago

I suppose this is a crate?

Indeed it is: https://crates.io/crates/cargo-apk

cargo-apk is part of the android-ndk-rs umbrella, so the answers you got in rust-windowing/android-ndk-rs#123 were relevant to cargo-apk.

Joe23232 commented 3 years ago

I see thanks mate =D