Creating a native background application using ndk - android-ndk

How to create more than 1 background applications in a single Android application using Android NDK ?
Need help in creating few background applications using NDK. My C application makes use of few standalone applications which run in the background (as services on windows). So my question is how can I create these standalone applications on Andriod platform?
I'm aware that these have to be services in Android applications, but services are Java code & NDK doesn't support C services & all my application code is in C. So how can I port these standalone applications onto Android along with my main application which uses these standalone helper applications. Should they be made separate libraries ?
If they are made separate libraries, then how can I ensure that they keep running in the background? I'm not sure, so any guidance will be very helpful. I don't want to root the device.

Android is very different from Windows, porting Windows services may be a significant challenge.
First of all, the IPC protocols are not the same, therefore you may need modifications to simply have your code compile.
The second issue is the background execution model of Android. On the newer versions, since Marshmallow, Google is improving the battery life by proactively killing all background services.
So, if you depend on these processes to be running always, you must keep your app in the foreground.
This said, you can build and run a command line executable for Android without wrapping it into an Android (Java) application or Service.
You can run them from the android shell (at least for testing), or use Runtime.exec() from Java. If you root the device, you can even start these executables on boot from init.rc, just as if it were a regular Linux box.

Related

Developing qt application for a remote device

I am not sure if this is a Programming or Linux question so please forgive me! Here is my situation:
I have my own PC (running Lubuntu 64 19.04) which I use as my work desktop. I have installed qt creator and qt 5.13 and everything works fine.
Now I have a mini-pc (intel nuc) which is luckily the same CPU architecture (intel x86-64). So the program will be binary compatible for both machines and allows me to develope and compile on my main machine and then remotely deploy or debug on the mini-pc using something like ssh and scp.
I want to develope some sort of "kiosk" application for this mini-pc. The problem is that it has very little storage (32GB). This kiosk application will save some data so it needs a lot of free space.
Now back to the question: For the mini-pc, I can go with qt-installer and install qt just like how I did it on my desktop. But I want to avoid this and I want only to copy the libraries that my application needs to have as small as footprint possible. So:
Is there a qt 5.13 libraries only package that I can install using
apt-get?
Can I get away with only copying (.so or .a) files to my remote pc
in the application binary folder?
What would be the must professional way?
You can copy only the relevant dependencies. There is a existing project for this purpose, called linuxdeployqt.
According to the official docs:
This Linux Deployment Tool, linuxdeployqt, takes an application as input and makes it self-contained by copying in the resources that the application uses (like libraries, graphics, and plugins) into a bundle.
And more specific:
When used on Qt-based applications, it can bundle a specific minimal subset of Qt required to run the application.
The project is based in the official tool macdeployqt.

VSCode and AndroidStudio Project setup to run flutter for device, web (and desktop?)

I have read a question/answer which states Flutter Web is a fork of Flutter and so one Android Studio (or VScode) project can't be built to handle both.
I'm not an expert on either (obviously) but I don't understand why the fact the libraries are forked implicitly precludes one from using the same source code for the different destinations.
Has anyone done so? And, if so, is there a skeletal project anyone would care to share?

MEF support on Xamarin.iOS

I am wanting to port a C# Mobile App for Windows 8 tablets using Xamarin. One of the issues we foresee is the use of MEF. Does Xamarin.iOS support MEF?
It depends on what you mean by MEF support. Using MEF assemblies is possible using Xamarin.iOS. What's not possible (iOS restriction) is dynamically loading code in your application (e.g. plugins).
You might be able to use MEF while ensuring there's not dynamic code being loaded, i.e. that everything is statically referenced and built inside a single binary executable (e.g. by ensuring every plugin is built-in).
Depending on your application that could prove useful (no, or less, need to modify your existing application) or not (if your app can't load/be built with all plugins). In the later case your problem is with iOS itself (not Xamarin).

How to run C# 4.0 app on Linux OS using mono?

I want to run my c# application with OS Linux using Mono. I am new to this cross platform migration? Please tell the procedure for doing that?
Thanks & Regards.
It very much depends on what type of application it is. For a console or WinForms app, it may be simple. Mono doesn't support WPF.
Well, the first think you'll need to do is install Mono of course. Then you probably want to run MoMA to determine your application's compatibility. There's a whole separate page about porting WinForms apps.
If all is well, you should just be able to run your application using:
mono MyApplication.exe
after copying the binaries over.
If your application is actually a web service or web application, you'll want to think about the various hosting options.
I suspect you'll want to read a lot of the pages on the Mono Start Page.
Check if your application is 100% compatible with Mono Framework using MoMA.
Remove or replace those unimplemented parts with Mono's implementation or third party libraries that works with Mono. Or if you think it should work fine, just execute it with Mono Framework 2.8 or higher. Better go with 2.10 which is default's profile is on 4.0.
There is an IDE, MonoDevelop that supports Web and Desktop applications. Open the project files (monodevelop supports visual studio project files) from monodevelop, compile and run.
you can browse mono website here, where you can find which features are supported and which are not supported and why.

What is Cygwin and how to use it in relation in Android NDK

Hi I am new to android NDK Devlopment.I downloaded Android NDK 4 for windows.I read through the docs.But i am not clear with it.
First thing is that,I want to develop the native file which may be c 0r c++.I think Using Cygwin will come to play.I dont have any idea or how to use cygwin .From the Docs i just read Cygwin is required for Windows platform.Apart from it ,i dont have any knowledge about it.
Not yet started with NDK Concepts.Help Required
Cygwin is a way to make Windows support some linux functionality. If you install cygwin on your windows machine you'd be able to run some linux software on windows (you'd have to recompile it especially for cygwin though). You can find it and more information about it here. There's also a good explanation at the wiki page here.
If the Android NDK needs it I suppose the Android NDK needs some linux functionality or tools to work properly. The other option might be to install Linux on a machine and run the Android NDK on there, it might be better since I assume Linux is the native environment for Android NDK development.
Since you're saying that you're a bit unclear about the NDK, you should probably be aware that as far as I understand you can not build a whole Android app using it, you can only develop bits of it, you will still need to develop at least part of the app to run on top of the Dalvik virtual machine, which, as far as I know, means that you'll have to write that bit in Java. In general I think that you should develop Android apps only in Java unless there is a specific reason to build certain parts of it using the NDK.
From wiki:
Cygwin (pronounced /ˈsɪɡwɪn/,[2] SIG-win) is a Unix-like environment and command-line interface for Microsoft Windows. Cygwin provides native integration of Windows-based applications, data, and other system resources with applications, software tools, and data of the Unix-like environment. Thus it is possible to launch Windows applications from the Cygwin environment, as well as to use Cygwin tools and applications within the Windows operating context.
Cygwin consists of two parts: a Dynamic-link library (DLL) as an API compatibility layer providing a substantial part of the POSIX API functionality, and an extensive collection of software tools and applications that provide a Unix-like look and feel.
So, Cygwin is a set of tools which allows you to emulate a unix-like (or linux) environment on your windows machines.
The NDK is the Android Native Development Kit. It allows you to write parts of your application in native code (C/C++) and integrate them into your application. Your application still runs under the Dalvik VM but it can load shared objects creating using a cross compiler. The NDK contains all the necessary tools and build scripts to generate native code binaries. It's an advanced concept and one you should probably wait on until you fully understand the architecture.
The reason why it requires Cygwin (or some flavor of linux) is because it uses GnuMake and other linux tools such as awk or Nawk. These tools are not available (or are really hard to use) on windows platforms, hence the need for at least Cygwin (though I would advise you do yourself a favor and just install linux).

Resources