How to include/use latest version of Opus codec in Android NDK - android

A complete novice question here. I am pretty familiar with programming in C/C++ on Linux environments. However, I have no experience whatsoever with Android environment, let alone when it comes to making an application with C for Android platforms.
I need to use opus codec in my application but it is not present in the default libraries of Android NDK. How can I add it?
Some sources on internet talk about Android.mk files. I am using the most recent version of Android Studio and there is no .mk files, only Cmake files.

According to this, it's as easy as
implementation "com.vcpkg.ndk.support:opus:1.3.1"
There are tons of tutorials and examples of how to integrate native code in an Android app. Generally this requires a Java (or Kotlin) wrapper and some JNI code on the C side. Consider also consuming the opus codec via ffmpeg (e.g. mobile-ffmpeg library).

Related

How do I create a shared library in C++ for both Android and iOS?

I am using LibGDX to write apps for both Android and iOS and I want to be able to add C++ code to my apps to optimize certain parts and to port some functions etc.
I have been searching the internet and tried to follow some tutorials, but did not find what I need.
How can I write a very basic C++ library which I can load in LibGDX? Which tools do I need to use? Visual Studio? I develop in Android Studio.
I think that I need an .so file for Android and an .a file for iOS, is that correct?
On both platforms, it's possible to include a precompiled library as well as C++ source code directly.
On Android, you'll want to look into using the Android NDK. This allows you to include native C/C++ code that can bridge over to Java. The connection between Java and C/C++ is managed with the JNI. It's a fairly tedious, awkward system for communicating between C++ and Java. You'll want to look into setting up an Android.mk makefile that specifies how to include your library (or source code) into your build.
On iOS, it's a little more tightly linked. You can have Objective-C++ files that can run both C++ and Objective-C code. If you're using Swift, it's a little different (bridging between Objective-C++ and Swift).
In some cases, when the platform (Android/iOS) provides functionality that is superior to what is possible or realistic with C++, you might find yourself architecting the code such that your C++ can reach out to the platform as needed. This means that you might have headers with separate implementation files per platform.
thing.h
thing_android.cpp
thing_ios.mm
The android app's Android.mk file will include thing_android.cpp (but not thing_ios.mm). This file could cross the JNI bridge to talk to Java as needed, whenever you need something from Android SDK.
The iOS app will include thing_ios.mm (but not thing_android.cpp). The .mm extension signifies Objective-C++, so that file could directly call powerful Cocoa libraries as needed.
Finally, on all platforms, you'll want to be sure to either scale back your usage of C++ to the lowest common denominator platform. In other words, if iOS supports a particular feature of C++, and Android doesn't, then you cannot use that particular feature.

Could I wrap c++ library to Adobe Air native extension for mobile IOS/Android

Can I wrap a C++ library to Adobe Air native extension IOS/Android?
I have a C++ library that was written by third party. I want to use that library for an adobe air native extension for mobile?
Will I be able to do it. If so, where can I find some guidelines?
I'll attempt to answer the Android part of the question.
I haven't seen it spelled out explicitly in the Adobe Air documentation that this is possible, but in the Adobe Help docs for Adobe Air, section Packaging a native extension: Building the native library, it says:
Android native libraries: When you use the Android NDK, provide a shared library with a filename as follows (etc)
The NDK as you may know lets you to implement parts of your Android app using native-code languages including C++.
I take it this reference in the docs means it's possible. As a starting point, I'd get familiar with the details of the NDK.
While this is not a detailed guideline on how to proceeed, I hope it provides a pointer in the right direction.
An alternative to building an ANE to wrap the C++ library is to compile it into Flash bytecode, using the new Adobe "C++ to Flash" compiler (previously known as Alchemy). It can produce a swf that you can later call from ActionScript. Here is a tutorial that explains how to do it. And here is its official website.
for iOS you can use the c library if you can statistically link to it. ANE on iOS does not support dynamic linking (as of 3.2 not sure if something changed in newer releases). Static linking is fairly easy process in Xcode just google it.
for Android:
If you have the .so file you can write your ANE in JAVA and use jni(System.loadLibrary) to talk to your cpp library. its better than writing ANE in CPP completely. See ane documentation "Including additional Android shared .so libraries in the ANE package" section to know more.

How to integrate C++ file into Android Application using JNI

I want to use C++ file in my android application via JNI but i don't know how to integrate C++ file and how to Compile and run it.
Please help me if anybody knows about it
You need to do NDK programming. 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.
You can use Android NDK for your requirements.
Android-NDK
The NDK is a toolset that allows you to implement parts of your app using native-code languages such as C and C++. For certain types of apps, this can be helpful so that you may reuse existing code libraries written in these languages and possibly increased performance.
Tutorial Advanced Android: Getting Started with the NDK
Using Android NDK create shared library of your C,C++ files and load that library at runtime from your Android application. Look at tutorial I linked.

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.

Porting C to Android using Android NDK

Has anyone used the Android NDK to port a Linux app? We have an SSL VPN solution at work which Openconnect (http://www.infradead.org/openconnect.html) works with, but there is currently no client (from Cisco or otherwise) on Android. Is using the Android NDK a feasible approach to get this to work?
Thank you in advance
The NDK is a good solution for porting C/C++ Apps. You need to do a thin java shell to pass over any input, init and exit the program.
If your C app requires STL or exceptions - there are modified versions of the NDK that support them.
The Android NDK is not for porting apps. It is for creating libraries that can be accessed from a standard Android Dalvik app via JNI.
So, if you have the source code to this project, and it results in a .so, and you can write a JNI wrapper for it, the NDK may be a solution for you. Considering the project you cite seems dependent upon scripts, I suspect that's not how it was set up for use.

Categories

Resources