Developing native C applications android without the NDK? - android

OK this is a strange one:
Is there a way someone can develop native C applications or libraries for Android without using the Android NDK?
What was happening before the NDK was released?
(It's not there for too long, I think it was released only one or two years ago).

Apparently, you can -- a friend of mine is a real Android guru and he managed to build a GCC-based native toolchain entirely by hand. He also fixed some missing parts in Android's libc. The main idea is the following: GCC has builtin support for the arm-elf-linux target, so with an appropriate build script, you can configure it to build for Android. However, you have to root the phone to run the resulting binaries. One even cooler thing is that because GCC is a self-hosting compiler, with the arm-linux-elf toolchain, you can recompile GCC once again and have the toolchain on the phone itself.

Before the NDK was released, the only officially supported way of developing Android applications was to use the Android SDK and writing your applications in Java.
As others have mentioned, it's possible to cross-compile some applications as completely stand-alone and run them on a rooted phone. The downsides of this should be obvious: very few people will be able to run your application (they also need to be root, plus you won't be able to get your application up on the Play store); and you might even run into compatibility problems yourself across different devices e.g. if you rely on dynamic linking against various libraries (which you might need to do in order to keep the size of the binary down).
TL;DR: it's possible, but severly limited, and not recommended.

You can compile your C code with an Android-compatible toolchain (such as CodeSourcery) and run it on a non-rooted phone, from its command line (for example through an SSH connection like SSHDroid).

Related

Are the libraries different that is building from android-ndk in different platform

I want to release my SDK. but I have no idea Do I have some unknown problems if I compile the .so from different platforms (Mac or Window using same ndk version).
I think it is same between different platforms but I didn't have windows platform to confirm.
So Are the libraries different build from different platforms?
Bluntly, you should not believe that compilers produce the same code on the same input deterministically. Many do, but many do not. This is especially true when using optimization. (This situation is improving now the problem is recognized). The consequence of this is no matter what you build on you must only release the exact binary you have tested.
That said, you can totally build with the NDK on multiple platforms. Many of the large games studios use Windows and Macs for development, and production builds are done on Linux continuous integration systems, so this is done in practice all the time. You are far more likely to run into trouble with any extra tooling you have than the ndk itself.
You can safely mix Android binaries built on Mac and Windows, but please make sure you use the same NDK release and same parameters (most notably, same APP_STL).
You can send your native libraries built on Mac to Java developers who work on Windows. They don't even need NDK and don't care which release you were using (as long as it works).

How do I execute a Fortran based program in Android

I have coded a program in Fortran an works perfectly in Windows, my question is if there is any way I can use it in Android.
I don't have the reputation to just make a comment, but I will answer the concern you raise of "not wanting to install compilers" to build fortran programs for android. On pretty much any operating system there are no default compilers for any language, so you have to install compilers (luckily for fortran on windows you even have a lot of options). For Android, right now, you have only one choice. That is to build your own custom version of the NDK gcc cross toolchain and force it to build gfortran and libgfortran. As of right now, gcc has been deprecated in the toolchain. Soon that won't even be an option. I have recently built the previous version of the NDK with gfortran using the following link:
https://github.com/buffer51/android-gfortran
The other problem you're going to run into is that depending on what kind of application you have on windows (command line, gui, webapp, etc.), you're not going to be able to run it on a typical android tablet or phone because there is no command line interface by default (you'll probably have to root the device to get one). The easiest way to develop a usable android app is to write a Java app (using the SDK), and then use JNI to interface with a fortran "library". Unfortunately, there is no straightforward way to compile and use your program on Android, and soon even the complicated ways (building a custom compiler) will get even more complicated.

Can a shared library (.so) file built for linux be included/linked and used in an Android application?

I am working on a project in which I need to include NGSpice simulation library in an Android application and of course be able to use it.
I tried including the NGSpice windows DLL in my android application using SWIG and Android NDK, but it turned out that it is not even possible, so now I started to think about building NGSpice as a shared library for linux.
And now my question is, can I use the linux shared library for NGSpice as it is in my Android application, or does it need to built differently somehow to work on my Android application.
Thanks.
No. Android typically has two key differences from a traditional linux:
1) It uses the Bionic C library and dynamic linker, instead of a more traditional set such as glibc.
2) Android is typically run on an ARM or 32-bit x86 processor (or in rare cases MIPS), while your desktop Linux library might be either 64-bit or 32-bit x86 code.
If you build a .so compatible with the architecture of the machine and with bionic's system library functions and dynamic linker, then it should be workable.
Alternatively, if you have something for a compatible architecture but the wrong libc, it may be possible to write your own loader to get it into memory in working form on a secured device, or on a rooted device it is possible to run a more traditional linux userspace (typically Debian derived) in a chroot. But neither of these would be easy to integrate into an Android application - for the latter you'd almost definitely have to pass work over via interprocess communication, and that might prove easier in the former case as well.
Your only really endorsed solution is to rebuild the library from source, using either the ndk build system, or an ndk-generated "stand alone toolchain" and the library's current build system.

Building Autotools for Android

Perhaps some of you are aware that there is an Android port of GCC 4.7.
I've tested it and it works perfectly, however when 'make' and 'configure' are out of the picture, it is rather useless.
What would it take to port Autotools, including make and configure to Android itself?
If you are wondering who in the world would develop on a phone, you are forgetting that some tablets run Android, though I myself have a phone.
make require nothing, but C library and shell; configure is actually shell script, produced by autoconf, which in turn depends on awk, m4 and diffutils. The hardest part is using autoconf and make with Android built-in shell, which is said to lack lot of functionality. Fortunately Android ports of bash already exist.
The most problematic part with porting GNU programming stack to Android is undocumented file hierarchy (device vendors tend to modify it on every whim) and severely lacking Bionic library. There is number of projects, trying to work around this issues (such as http://sourceforge.net/projects/droidoverlay/, for example), but generally this area is still to be explored.

can native only code run on android as standalone application

We want to migrate a huge complex native program to Android system ,running it as a background service accepting command sent from Java Program using JNI along with IPC. However, the Android NDK state following words:
Please note that the NDK does not enable you to develop native-only applications. Android's primary runtime remains the Dalvik virtual machine.
Does that mean we have no way to run an standalone native-only application on Android as a background service? The native code can only exist in the form of library that will be loaded to the virtual machine through JNI?
The NDK itself is only for creating libraries, though if you do some web searching you will find that there are at least two sets of wrapper scripts or instructions for (ab)using its toolchain to make standalone executables linked against android's bionic libc (something you would not get from a non-android arm toolchain).
The google folks do not encourage people to do this. Unfortunately, their vision of android only includes java applications, with optional native libraries in support - it does not include any "stable" means of installing or launching a native executable, in the sense that they warn the methods you might be able to use today may not continue to work in new versions. This is really too bad, as it means giving up a lot of the general-purpose-computer potential of the device.
Well, it can be done. But to be honest i've never tried it using the NDK, but i've managed to create native applications using the toolchains provided with the android source code.
Your phone (incase your talking about phones) should be rooted.

Categories

Resources