I was wondering if writing apps in C++ in Android Studio is possible. I have some knowledge in creating apps in Java but I am more comfortable with C++, and is this a complicated process?
You can use Qt and create Android apps with C++ (http://doc.qt.io/qt-5/androidgs.html).
To setup Android Studio with Qt https://wiki.qt.io/Android
You can add C and C++ code to your Android project by placing the code into a cpp directory in your project module.
When you build your project, this code is compiled into a native library that Gradle can package with your APK.
Your Java or Kotlin code can then call functions in your native library through the Java Native Interface (JNI). If you want to learn more about using the JNI framework, read JNI tips for Android.
You can also use JNI to run c++ code (as a matter of fact c++ shared library or so) from Java.
Here you can find a usefull article + sample for how to do it.
Related
I have looked at Use prebuilt JNI library in Android Studio 3.1 and How to use .so in a second project in Android?. The first is trying to get a library file without headers working and the other seems to be focusing on a specific issue with his build (although there's some useful information there). I'm relatively new to app development and especially to native development on android. I've gotten a build with the JNI library and some c++ code working, but that seems to be just for building from source.
It's probably a simple answer, but I haven't been able to find documentation on this specifically in the android developers documentation. I'm interested in understanding the correct (or most conventional) place to put and way to use a precompiled library (module/lib/*.so and module/include/*.h) in an android project. Would I even need to use JNI or the NDK if the library is built with another build tool? Another project I have has a native library source object (*.so) in ./obj/local, ./libs, and in many other folders related to JNI. I'm guessing it would be somewhere in there, but I'd like to know what is conventional.
For some context, I'm trying to work with the essentia library. I have followed the guide on compiling for Android and have a build with the general hierarchy mentioned above (essentia/lib and essentia/include) that seems to be working.
I have read the overview for Android Library project. I have in mind to develop an Android project library containing native libraries and JNI wrapper which would be included into the Android project. However, the doc does not explicitly mention if Android library project can include native libraries.
Can anyone confirm/infirm support for native libraries in Android library projects ?
As Android Document said:
An Android library project is a development project that holds shared
Android source code and resources.
An Android Library Project, in fact, isn't so different from normal Android project. You can make a normal android project as library project, except asset folder. They're just different when you declare in Eclipse Buid Path or something similar in other IDEs.
Native support simply, just a call to native layer (as in your post, Native Library) such as C/C++ library file (*.so file). This function is not specific to Android, but in normal Java project also support this feature: Calling functions from another language inside Java.
So, in short answer, yes :)
I have a huge C++ library for image processing. I would like to use this DLL library in an Android project. How can I call methods in the C++ DLL library in Android?
Maybe you can try JavaCPP. JavaCPP will help you auto generate appropriate code for JNI, and passes it to the C++ compiler to build a native library.
For more details and examples, please seeļ¼ https://code.google.com/p/javacpp/
via JNI Java Native Interface.
using this keyword will let you find a tutorial:
http://developer.android.com/training/articles/perf-jni.html
You need the Java Native Interface (JNI)
Oracle has a great set of tutorials on it (google for them).
Also, since you tagged your question Android, I'm presuming that's the platform you need JNI on.
You'll have to look into the Native Development Kit, more info on that here: http://developer.android.com/tools/sdk/ndk/index.html
I want guidance on how to port the opensource openSMILE http://opensmile.sourceforge.net/ library which is in C++ to Android. Specifically how should I use SWIG to create the caller code in JAVA and how should I use the Android-NDK to create the JNI in my android app? I have absolutely no experience with Android programming so I am not sure of how to start.
Please see Version 2.3. of openSMILE from http://opensmile.audeering.com/.
It contains an Android Studio example project with JNI interface and build scripts to compile library and binary for Android with NDK.
how to port the opensource openSMILE.?
You can download whole source code of that library and then cross compile it for your platform then install it in android stack or use it in jni
Specifically how should I use SWIG to create the caller code in JAVA..?
Here you need to write wrapper for each API of that library in jni c then you will have java exported API of that library which you can use in your android application.
I am building a multi-platform SDK for real time 3D applications. This SDK is programmed in C++ and works under Windows, Apple's iOs, MacOS, Linux and Android.
The project structure is complex, it consists in 3 native C++ static libraries, linked with some external static libraries in a complete shared library. This is very simple under all the managed OSes, except for Android.
The major problem in Android is bi-directional communication/calls between native code and Java code. I got this solved some time ago using SWIG to wrap the shared library's classes. To achieve that I wrote our my own build scripts (Makefiles) to handle native compilation with the ndk r4, swig code generation, java pre-compilation and jar creation.
Lately we added some callback/listener classes in the C++ layer, that we wanted to be derivable/overloadable in Java, for this we used SWIG's directors feature. But it appears that it needs JNI features (weak global references) that were not in the NDK r4b. So we need to switch to a newer Android NDK (r6b) that has these features. But since our custom build scripts were written for NDK r4b they won't work anymore.
My concern is to have everything built properly through Android's NDK/SDK (eventually through Eclipse) with Android.mk files so we don't have to rewrite everything from scratch each time we switch to a new NDK.
I'd like to know if there is a way to manage such complex project structure with standard Android.mk, ndk-build, ant and eclipse (including the SWIG part). And if so, how ?
Don't hesitate to ask for precisions, I am not sure I am being really clear.
Any help greatly appreciated.
Florent Lagaye.
I've been looking for a similar thing and, although I haven't figured it out yet, there is a good example with building gstreamer on Android.
http://cgit.collabora.com/git/user/derek/androgenizer.git/
It supposedly works with any libtoolized application.
Here is the directions for how to build:
http://gstreamer.freedesktop.org/wiki/GstreamerAndroid_InstallInstructions
What we ended doing is writing specific rules in the Android.mk file to manage swig interface generation.
Remember to add the generated c++ source to the list of source files before including BUILD_STATIC_LIB or BUILD_DYNAMIC_LIB, and to instruct swig to generate the java source in folder accessible by your Android java project.