Skip to content
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

Is it possible to run Linux GUI applications using android-ndk-rs? #177

Closed
Joe23232 opened this issue Aug 10, 2021 · 9 comments
Closed

Is it possible to run Linux GUI applications using android-ndk-rs? #177

Joe23232 opened this issue Aug 10, 2021 · 9 comments
Labels
type: documentation Awareness, docs, examples, etc.

Comments

@Joe23232
Copy link

There is an application called Termux that allows you to run Linux terminal based applications on it such as htop etc (probably I would have to recompile it to get it to work on ARM).

So using the android-ndk-rs crate, does it offer something similar to termux so that I can easily port any of my Rust programed Linux applications to Android?

@MarijnS95 MarijnS95 changed the title Is it possible to Linux based applications using android-ndk-rs? Is it possible to compile Linux based applications using android-ndk-rs? Aug 10, 2021
@MarijnS95
Copy link
Member

The android-ndk-rs crate, and in particular cargo apk help cross-compiling native libraries and binaries with the toolchain from the Android NDK, that are subsequently packaged in an APK. The resulting binaries (obviously) run on the device as well as inside Termux, but the main goal is to create APKs that use Androids NativeActivity to show an activity on screen, not terminal applications.

There are issues around where users successfully use cargo apk check/cargo apk build to build just the native binaries, and manually copy them out of target/<arch>-linux-android/debug/<your executable> to the device. cargo-ndk exists too, and solely compiles Rust crates to Android-targeted binaries using the NDK, but without providing the additional steps and tooling to package APKs, using the NDK and creating native activities. It is a bit unfortunate that these tools (their code-base) isn't unified as they achieve the exact same goal up until that point.

Note that Termux provides a Linux (Ubuntu/Debian based) environment with lots of common packages to perform tasks on UNIX and develop applications. In that sense it has very different goals than android-ndk-rs and can in no way be called "similar", but together they form a very powerful combination. Here's what you can do:

  • Install rust inside Termux and compile, develop and run your applications on-device directly!
  • Use cargo-ndk or cargo-apk to cross-compile your applications from a PC to run on an Android device. Deploy the resulting binaries to your device and use them from a terminal emulator like Termux.

In order to fully answer your question, I need one bit more information: what kind of "Rust programed Linux applications" are we talking about (console/REPL only?), and where do you intend to run them (directly on the device via eg. an adb shell, started from a Java application using System.exec, or from a terminal emulator like Termux)?

@Joe23232
Copy link
Author

Joe23232 commented Aug 10, 2021

@MarijnS95 Just a question what is the difference between android-ndk-rs vs cargo-apk vs cargo-ndk? I understand you explained to me how cargo-ndk works but how does it compare to the other two?

The resulting binaries (obviously) run on the device as well as inside Termux,

So if it is a terminal based application (something like htop for example), then can I get it to run without Termux, even if it does not show an output?

but the main goal is to create APKs that use Androids NativeActivity to show an activity on screen, not terminal applications.

So say if I made another htop (written in Rust), it would obviously work on Termux, but would it also work on NativeAcitivty, is NativeActivity an alternative to Termux but it is built into Android?

@MarijnS95
Copy link
Member

@Joe23232 Before answering your questions, take some time to familiarize yourself with the following information, readily available:

  • See the available crates provided by this repository, android-ndk-rs, by looking at the README. All crates have their own REAMDE too, explaining what they are for;
  • Termux is an app that provides a terminal emulator (a way to type and see the output of commands directly on the screen of your phone), and at the same time provides the Linux environment to make it usable because the environment on your phone (reminder: Android runs a Linux kernel too) is pretty bare-bones.
    You linked their home-page. Please read it, as it explains exactly what it does and what to use it for;
  • NativeActivity is a special way to write Android apps fully in native code, no Java required. It is usually used for games, and you'll have to perform all drawing yourself.
    https://developer.android.com/ndk/guides/concepts#naa

@MarijnS95 MarijnS95 added the type: documentation Awareness, docs, examples, etc. label Aug 10, 2021
@dvc94ch
Copy link
Contributor

dvc94ch commented Aug 10, 2021

My guess is that alacrity could be built with cargo-apk and you could somehow get something to work. Doing unsupported things is interesting, but it means you're on your own.

@Joe23232
Copy link
Author

Joe23232 commented Aug 10, 2021

I see thanks guys.

Also is there a GUI library that works on ANdroid, for example Iced or something?

@dvc94ch
Copy link
Contributor

dvc94ch commented Aug 10, 2021

People have gotten iced to work on Android. Would be exciting to get support upstream, working out the quirks and adding an example to android-ndk-rs.

@Joe23232
Copy link
Author

@dvc94ch DId they have to do some hacky way to get it to work or it just worked?

@dvc94ch
Copy link
Contributor

dvc94ch commented Aug 10, 2021

@Joe23232
Copy link
Author

cool thanks

@dvc94ch dvc94ch closed this as completed Aug 10, 2021
@MarijnS95 MarijnS95 changed the title Is it possible to compile Linux based applications using android-ndk-rs? Is it possible to run Linux GUI applications using android-ndk-rs? Aug 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: documentation Awareness, docs, examples, etc.
Projects
None yet
Development

No branches or pull requests

3 participants