Is it possible to use CLI - Command Line Interface in Android NDK?? Is there such a function: exec (query)?
Ie is it possible to make queries from the command line C program?
officiallyi have never seen commandline programs on android, whether written in java or android ndk.unofficiallyi have seen commandline c/c++ programs targeting arm processors and the authors claimed they run on android eg follow this link to whet your appetite
My thoughts?Should you write such 'unofficial' applications, i doubt that you will be able to distribute them to your customers eg through the android market since android applications are dalvik executables(kind of java applications compiled and optimised for the dalvik virtual machine)
Related
I'm looking to build a new app written in Java, can I write one code that can be executed both on an OS running Linux and OS running android? Or do I need to write two different codes one for each system?
Theoretically yes.
Android apps run in a Dalvik Virtual Machine, that comes with a Java language implementation that compiles down to Dalvik bytecode, but not to JVM bytecode. So, the code has to be written in Java or some language that compiles to Dalvik VM bytecode that uses the Android API.
However, the virtual machine runs on top of the underlying Linux OS, and there are ways to call native code. See NDK documentation.
So, it is technically possible to run native Linux programs on Android, as there is a Linux kernel running beneath everything.
I am collecting some data from my android application. How to run a python script in my android application that uses the collected data as input and generates some output?
Consider Jython, Jython is an implementation of the high-level, dynamic, object-oriented language Python seamlessly integrated with the Java platform. The predecessor to Jython, JPython, is certified as 100% Pure Java.
mbedded scripting - Java programmers can add the Jython libraries to
their system to allow end users to write simple or complicated
scripts that add functionality to the application.
Interactive experimentation - Jython provides an interactive
interpreter that can be used to interact with Java packages or with
running Java applications. This allows programmers to experiment and
debug any Java system using Jython.
Rapid application development - Python programs are typically 2-10X
shorter than the equivalent Java program. This translates directly
to increased programmer productivity. The seamless interaction
between Python and Java allows developers to freely mix the two
languages both during development and in shipping products.
The awesome features of Jython are as follows,
Dynamic compilation to Java bytecodes - leads to highest possible
performance without sacrificing interactivity.
Ability to extend existing Java classes in Jython - allows effective
use of abstract classes.
Jython doesn't compile to "pure java", it compiles to java bytecode subsequently to class files. To develop for Android, one compile java bytecode to Dalvik bytecode. To be honest, this path of development is not official , thus you will run into lots of problem with compatibility of course.
You may use qpython,
QPython is a script engine that runs Python on android devices. It
lets your android device run Python scripts and projects. It contains
the Python interpreter, console, editor, and the SL4A Library for
Android. It’s Python on Android! It offers the development kit which
lets you easily develop Python projects and scripts on your Android
device.
If you need to add some specifics libraries, according to qpython documentation install-libraries :
You can install most pure python libraries through pip_console.py
which included from the 0.9.8.2 version
You may add --no-use-wheel argument when using pip_console.py to avoid unknown archive format :whl issue when installing some package.
and / or
You can upload your libraries into the
/sdcard/com.hipipal.qpyplus/lib/python2.7/site-packages or
/sdcard/com.hipipal.qpyplus/lib/python3.2/site-packages (For QPython3)
Regards
I don't know whether i make sense or not. But just wanted to now that can i run the c/c++ code in android without the need of writing JNI wrapper or using Native Activity way?
I mean, I am having a simple C++ Template Matching code which contains main function and I use to run it using g++ in terminal.
Now I want this Template Matching code to be run in android usng NDK. Is there any way? I have googled a lot but all they is to either use JNI wrapper or use SWIG which makes JNI wrapper, but can't actually get into any of them. I need more simpler solution.
If you have a rooted phone, you can compile and run programs as on any linux machine, from the adb shell.
However, that requires a bit of knowledge about Linux.
So, to start:
Root your phone (force it to give you admin privileges). That is easy for developer phones/boards, and a kill for regular phones bought at a shop downstreet.
compile your app for android and run it from adb as you would do from a linux shell.
Here is a more detailed answer on the matter
How to compile C into an executable binary file and run it in Android from Android Shell?
Hi I'd like to know how to compile an app source code on an android platform?
I know it's possible because I saw some apps that are doing it...
Thanx ahead!
I think what you are asking for is a way to compile android apps on an android device.
the way an app like this new IDE does.
If so what you would need to do is to take an open source java compiler such as the ejc (the Java compiler used within Eclipse) and use it to compile your java source. You would then need to port the dalvik compiler to be able to run, in order to generate dex from the class files generated by the java compiler.
An interview with he developers of AIDE has a little bit more info on how they did it.
UPDATE:
Actually I just came across an open source project which provides similar functionality but based on using vim and the existing SDK cli tools ported to run on a an android device. The project is hosted here.
UPDATE 2:
I found yet another open source project that also does on device compile/build which I think should provide you with examples of what you are trying to do...
More specifically, if you look in IDE.java, you can see how the individual tools (ejc, dx, aapt) are called/used.
Possible in a number of ways...
There have been apps - proprietary & open source - built for the purpose. I am not sure if these apps will be at least near the production quality. But they work:
It mainly depends on language you are writing - since cross platform app development is also possible on Android.
• Java: Java N-IDE, AIDE
• JavaScript: NativeScript CLI, Appcelerator Titanium CLI, Apache Cordova via CLI. [All these can be installed via node.js package manager (npm) which in turn can be installed via Dory NodeJS, GNURoot Debian or Termux apps..
• Linux CLI utilities can be installed on Android simply with a terminal shell or GNURoot / Termux. You can also Emulate complete PC OS using Limbo PC Emulator / Bochs [Although they should be lightweight]. In theory, by this way you should be able to use almost all Android development utilities. But Storage, memory & performance constraints come to play..
• There are other apps & web services for hobbyists: eg: Sketchware, DroidScript, Appy Pie, Monaca, PhoneGap Build and many others.... But don't expect professional quality apps using them..
Q1) I want to run a simple c program on android emulator.I am using windows xp os on my machine. I have installed sdk, jdk, eclipse for android development and succeeded running android application on AVD.
Q2) I just need to know is there any way to run a C program(without any java) on AVD. On my machine I have installed arm and using that I have compiled a C program.
Q3) I also want to know is it possible to push the compiled binary into android device or AVD and run using the terminal of the android device or AVD?
You can compile your C programs with an ARM cross-compiler:
arm-linux-gnueabi-gcc -static -march=armv7-a test.c -o test
Then you can push your compiled binary file to somewhere (don't push it in to the SD card):
adb push test /data/local/tmp/test
if you have installed NDK succesfully then start with it sample application
http://developer.android.com/sdk/ndk/overview.html#samples
if you are interested another ways of this then may this will help
http://shareprogrammingtips.blogspot.com/2018/07/cross-compile-cc-based-programs-and-run.html
I also want to know is it possible to push the compiled binary into
android device or AVD and run using the terminal of the android device or AVD?
here you can see NestedVM
NestedVM provides binary translation for Java Bytecode. This is done by having GCC compile to a MIPS binary which is then translated to a Java class file. Hence any application written in C, C++, Fortran, or any other language supported by GCC can be run in 100% pure Java with no source changes.
Example:
Cross compile Hello world C program and run it on android
You need to download the Native Development Kit.
If you want to compile and run Java/C/C++ apps directly on your Android device, I recommend the Terminal IDE environment from Google Play. It's a very slick package to develop and compile Android APKs, Java, C and C++ directly on your device. The interface is all command line and "vi" based, so it has real Linux feel. It comes with the gnu C/C++ implementation.
Additionally, there is a telnet and telnet server application built in, so you can do all the programming with your PC and big keyboard, but working on the device. No root permission is needed.