Difference between SDK and NDK in android - android

Since 2 Years I am working as Android Application Developer. I generally use android SDK for all the Android Apps Development. Now I have a project which is an Android App in which I have to use SDK as well as NDK for App development (As per Client requirement).
But as I don't have any experience with NDK I don't know what is it. In some Blogs I have read that NDK development is based on c++.
Is it true that to work with NDK one must have the complete knowledge of c++ ?
Please Help !!

Use of NDK means you have to write portion of code in C/C++ just to achieve the speed. If it is client requirement then you have no option. But keep in mind that you should use NDK only when you feel you need better performance. And of course you must have some understanding of c/c++ to use NDK.

NDK
NDK is a set of tools to compile C code to shared lib,
which you could use in your app - and that's all.
Enables legacy code re-use between iOS and Android platforms
Good for implementing CPU intensive operations that don't
allocate much memory like signal processing, physics simulations.
SDK
SDK is the main development kit for Android apps - it contains tools for Java and resources (png, xml) compiling, packaging to apk file, installing, running and debugging them on a device, an emulator, documentation, etc.
Java has superior memory management model Superior threading model Better exception handling model Rich set of libraries Superior support for unicode characters.

Related

Difference Between opencv and Android opencv

I have been wondering if it is possible to use all the functions of opencv in android opencv. I am planning to do my PG project in android Open CV. Because i am familiar with android but not opencv. Is it possible to implement all the functions used in opencv (windows) to Android opencv?
Unfortunately, Java API doesn't provide access to all the functions as in the case of C++ API. First, I will discuss what all the toolkits that are needed for doing so and then how can we use the native(C / C++) in Android.
Toolkits Needed
To develop Android apps using OpenCV Library, we need the following tools (all of these are either Open Source or free software, or both) -
Eclipse with ADT Bundle (You can choose any other IDE like Android Studio)
OpenCV4Android (although, you can compile from source code, it is recommended for novice users to download the binaries.)
CygWin (Only for Windows, not needed on Linux or Mac)
Java JDK (JRE would not be sufficient)
Android Native Development Toolkit (NDK) (needed to run native C/C++ code)
You will need to set environment variables on your OS for the tools to correctly configure.
Alternatively, nVidia also provides a suite of developing tools — TADP. The advantage of TADP over the piece-by-piece method is that you don’t need to follow the often perplexing task of setting up the development environment. The default installation will download a lot of superfluous packages that are not needed (The download size can be greater than 2GB and on slow internet connections, it can turn into a prolonged activity.), rather select the packages manually at the time of download (A dialog box will appear, asking you to select either Complete, Custom or Manually.)
Using C/C++ code in Android
You can get access to native C/ C++ functionality in Android by
Here is the official OpenCV tutorial on setting up .
Also, Check out the Mixed Processing Sample in the Samples folder of Android4OpenCV folder. This example shows how you can pass an image and its grayscale equivalent to a native function and detect features on the image using FAST features detection.
Useful books and tutorials
There is not much study material right now, but I guess these 2 source are the best -
Android Application Programming with OpenCV by Packt
Publishing.
Sample programs in the OpenCV4Android folder.
Yes it is definitely possible to use all funtions in OpneCV on Android. But you have to note that OpenCV4Android includes 2 parts: the Java part and the native part.
In fact the Java part provides most of the functions of the OpenCV library. If you would like to have access to more functionalities and faster speed, then just go for native development. The .so library in the OpenCV SDK pack provides all native functions. In fact if you are familiar with native development, you could even directly use the OpenCV c++ library, just like how people use FFMPEG on android.

Port .NET dll to different platforms

I have a dll based on .NET 2.0 with full source code access.
So I can build it in VS2010.
I need to port this to Android/iOS/MacOS.
As a result I expect some equivalent of dll for each platform.
So another programmer can link (doesn't matter how) this equivalent to his own project at one of that targeted platform.
For example I ran MonoDevelop on Mac and don't see how I can build my .NET project and to receive such equivalent of dll.
So I need help to find solution and understand what to do to receive requierd result.
There are CLI implementations, primarily Mono, that work on both iOS and droid. The simplest tools here are MonoTouch and Mono for Android, both available from Xamarin. With these tools, you can build and test your dll targetting the relevant frameworks. Another programmer, again using the MonoTouch or Mono for Android tools, can reference those dlls, and build their application, with all the tools necessary to package and deploy (side-loading or via, say, the device's store) an application using that library. This deployment will typically also include all the runtime/framework pieces needed by the application.
MonoTouch makes use of the MonoDevelop IDE, so will be familiar to you as a MonoDevelop user. Mono for Android can do that (i.e. be hosted inside MonoDevelop), but can also be used inside Visual Studio.
Running .NET code requires a .NET runtime to be installed. Neither Android nor iOS devices come with such a runtime preinstalled.
In theory, you could install the Mono Runtime (a open-source .NET alternative) on an Android device or a jailbroken iPhone/iPad. However, as I understand it, you're looking for a way to create a library to give developers, so this isn't a good solution.
However, what could work is creating a library with MonoTouch. MonoTouch compiles your .NET code to a binary that iOS devices can use - regardless if they're jailbroken or not, without needing a runtime installed.
If you follow best practices, you might port your library successfully, such as
http://sharpsnmplib.codeplex.com/discussions/390251
However, it purely depends on the characteristics of your library, which you does not mention yet.

Android-Ndk vs Cross-Compile? Both work, but what was the need of Android NDK then?

I can cross-compile any C/C++ application, statically link it Linux libraries and run it on Android. What was the need of an Android-ndk then? Android-ndk limits us to bionic which has a small subset of gnu libc. Isn't it a better idea to straightaway cross-compile applications and run them through Android shell? Is there any limitation to cross-compiling that I can't see? This URL : Can Linux apps be run in Android? answers my question to some extent but eventually leaves me confused and without clarity.
I think this is enough for Android-NDK
The Android NDK is a companion tool to the Android SDK that lets you build performance-critical portions of your apps in native code. It provides headers and libraries that allow you to build activities, handle user input, use hardware sensors, access application resources, and more, when programming in C or C++. If you write native code, your applications are still packaged into an .apk file and they still run inside of a virtual machine on the device. The fundamental Android application model does not change.
The NDK provides:
A set of tools and build files used to generate native code libraries
from C and C++ sources
A way to embed the corresponding native libraries into an application
package file (.apk) that can be deployed on Android devices
A set of native system headers and libraries that will be supported
in all future versions of the Android platform, starting from Android
1.5. Applications that use native activities must be run on Android 2.3 or later.
This thing you can not find in other cross-compilation with arm toolchain..
As mentioned in the link http://developer.android.com/sdk/ndk/index.html NDK is a companion for App development folk to create performance sensitive native code. NDK exposes some of the native implementation of Android which could not be found in the general Linux environments. Some of them include the Android/Bitmap, Android/nativeWindow etc. Using these Android natives applcation can speed up CPU intensive processes like some compression or decompression of images.
Even though the externally cross-compiled executables may run in the Android there no guarantee that versions of the standard library implementaions are the same. NDK provides a easier and Android compatible toolchain and other resources, using which is much easier to application developers than having to find a compatible cross-compiler for their usecase.

How to create Android apps using Delphi

I have been asked to research on how to make an android app using Delphi, Now I am not sure that this can be done. I have not come across tutorials on the same. Somebody please clarify on this issue.
Delphi cannot create Android apps at present. This is being worked on for a future release.
Update: As of the release of XE5, Delphi now supports Android development for certain ARM hardware using the mobile Delphi compiler.
Free Pascal is now able to produce code for the Java platform - so it might be feasible to create Delphi code which can be compiled to Java bytecode with FPC and then converted for the Dalvik VM.
The FPC backend for the Java Virtual Machine (JVM) generates Java byte
code that conforms to the specifications of the JDK 1.5 (and later).
While not all FPC language features work when targeting the JVM, most
do (or will in the future) and we have done our best to introduce as
few differences as possible.
This FPC JVM backend is not related to Project Cooper by RemObjects,
nor does FPC now support the Oxygene language.
Two choices to follow at present - check out Delphi for Android which is in design/beta phase: http://lenniedevilliers.blogspot.com/
Or, use Prism http://www.embarcadero.com/products/prism (and check out their Oxygen for Java coming soon http://www.remobjects.com/oxygene/java.aspx which is in Beta)
With DWS as backend script compiler and the soon to come Smart Mobile Studio (aka OP4JS) component library and RAD interface it will be possible to make apps running with HTML5 in android applications (and iOS or any other html5 compatible system).
By using object pascal, all Delphi and freepascal users will have a short learning curve and a high code reuse factor.
There are some samples using only the DWS backend here :
taming-the-flock-with-object-pascal
taming-html5-verlets-with-object-pascal
Update :
More samples can now be found on their homepage.
First steps with native Android applications made with Lazarus/FPC are here.
One way is to use a combination of Delphi, Sencha and PhoneGap by leveraging the Raudus framework. You can try the RaudusEmployee.apk example on your phone and see if this method will work for you.
http://www.raudus.com/samples/
This is not a native application, but similar to many new HTML5 applications.
Delphi XE5 is now released with Android support.
http://www.embarcadero.com/products/rad-studio/create-android-apps

What is the Android Native Development Kit (NDK)?

What is the Android NDK (native development kit) ? How can one use it? Why should one use it?
The NDK (Native Development Kit) is a tool that allows you to program in C/C++ for Android devices. It's intended to integrate with the SDK (it's described as a "companion tool") and used only for performance-critical portions of a project. See here for more information.
NDK may improve application performance. This is usually true for many
processor-bound applications. Many multimedia applications and video games use
native code for processor-intensive tasks.
The performance improvements can come from three sources. Firstly, the native code is compiled to a binary code and run directly on OS, while Java code is translated into Java
byte-code and interpreted by Dalvik Virtual Machine (VM). At Android 2.2 or higher,
a Just-In-Time (JIT) compiler is added to Dalvik VM to analyze and optimize the Java
byte-code while the program is running (for example, JIT can compile a part of the
byte-code to binary code before its execution). But in many cases, native code still
runs faster than Java code.
Java code is run by Dalvik VM on Android. Dalvik VM is specially designed
for systems with constrained hardware resources (memory space, processor
speed, and so on).
The second source for performance improvements at NDK is that native code allows
developers to make use of some processor features that are not accessible at Android SDK,
such as NEON, a Single Instruction Multiple Data (SIMD) technology, allowing multiple
data elements to be processed in parallel. One particular coding task example is the color
conversion for a video frame or a photo. Suppose we are to convert a photo of 1920x1280
pixels from the RGB color space to the YCbCr color space. The naive approach is to apply a
conversion formula to every pixel (that is, over two million pixels). With NEON, we can process multiple pixels at one time to reduce the processing time.
The third aspect is that we can optimize the critical code at an assembly level, which is a
common practice in desktop software development.
Disadvantage
NDK cannot access lots of APIs available in the Android SDK directly, and developing in NDK will always introduce extra complexity
into your application.
The Android NDK is a companion tool used only in conjunction with Android SDK which allows application developers to build performance-critical portions of their apps by use of native (C/C++) code.
This provide benefits in form of reuse of existing code and increased speed.
Please go through below links.
Link-1
Link-2
Link-3
The Android NDK is a companion tool to the Android SDK that lets you build performance-critical portions of your apps in native code. It provides headers and libraries that allow you to build activities, handle user input, use hardware sensors, access application resources, and more, when programming in C or C++. If you write native code, your applications are still packaged into an .apk file and they still run inside of a virtual machine on the device. The fundamental Android application model does not change.
The following links also answers your question:
What is NDK?
When to Develop in Native Code
NDK Download
How to build NDK app
how to work with NDK
10 tips for Android NDK
The Android NDK is a toolset that lets you embed components that make
use of native code in your Android applications.
Android applications run in the Dalvik virtual machine. The NDK allows
you to implement parts of your applications using native-code
languages such as C and C++. This can provide benefits to certain
classes of applications, in the form of reuse of existing code and in
some cases increased speed.
Source: http://developer.android.com/sdk/ndk/overview.html
The Android NDK is a companion tool to the Android SDK that lets you
build performance-critical portions of your apps in native code. It
provides headers and libraries that allow you to build activities,
handle user input, use hardware sensors, access application resources,
and more, when programming in C or C++. If you write native code, your
applications are still packaged into an .apk file and they still run
inside of a virtual machine on the device. The fundamental Android
application model does not change.
Source: http://developer.android.com/sdk/ndk/index.html
NDK is just a set of tools which lets you to write C/C++ codes for your application.For example suppose you want to add a critical function/performance to your app and you want to write it in C/C++ then eclipse or any other IDE will not allow you to write your C/C++ and in that case you have to use NDK and integrate it in your app.
NDK is a toolset that allows you to implement parts of your app using native-code languages such as C and C++....Checkout this https://developer.android.com/tools/sdk/ndk/index.html
Android NDK (native development kit)
Android Native Development Kit (NDK) is developers to write code in C/C++ that compiles to native code
Why should one use it?
The source code is compiled directly into machine code for the CPU (and not into an intermediate language, as with Java) then developers are able to get the best performance
How can one use it?
Here best tutorials
https://developer.android.com/ndk/index.html
https://www.androidauthority.com/android-ndk-everything-need-know-677642/
https://www.ntu.edu.sg/home/ehchua/programming/android/Android_NDK.html

Categories

Resources