0

I have written a very basic program in C++. It only interacts with the user via text from the console.

How can I turn this into an app for my android phone? I just want to do the exact same thing, interact via boring text in a black screen (no graphs, no fancy interface, no nothing)

Is there a simple way to achieve that? I was told that I should translate my program into Java, and then go from there; is that the only way, or better, the simplest way?

1
  • As you tagged Android, here is the developer site (tools are free): developer.android.com Commented Mar 27, 2019 at 0:36

1 Answer 1

1

As far as I know, you will need a Java UI even for "boring text in a black screen". (The project https://github.com/jraska/Console looks like it might help with that. But note I haven't used it, can't vouch for how it works, and might be mistaken about what it does.)

But you probably don't need to translate absolutely all your C++ code to Java. The official Android Developer page https://developer.android.com/studio/projects/add-native-code describes how to include C++ code into an Android app, using the Java Native Interface (JNI). You will need to provide interface functions using JNI so that the Java code can call the C++ functions. And you may need to generalize how your C++ code handles input and output, e.g. to use streams or strings instead of std::cin and std::cout directly.

Sign up to request clarification or add additional context in comments.

2 Comments

No JNI is actually needed: a simple textual native executable can be wrapped in an Android Java terminal emulator app, and operate via normal methods like stdin/stdout etc. Using JNI is an option, but requires some awareness of the fact that the code is then a library of a process managed in... interesting ways - particularly one where process level state is strongly de-emphasized.
@ChrisStratton Sounds like maybe you could write a better answer?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.