Creating APK file from VS2013 C++ code - android

I have developed a library for Windows in VS2013. It does not have a GUI, only (mathematical) code.
I would now like to create an APK file so that I can use my library on Android.
I hope that I don't have to re-write everything from scratch for Android.
What would currently be the best solution so that I can keep most of my C++ files while creating the APK?
Thank you for the help!

You can compile your library with the Android NDK, which produces a .so file.
Android applications are written in Java. To use your library, you should first load your .so library and then you can access its function via JNI.

Related

Where does a native *.so library and its headers go in an android project?

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.

Writing apps in C++ in Android Studio?

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.

Working with .a library in Android Studio project

I have to use an external library with '.a' extensión but I do not have any idea how to use it. I am totally lost, I don´t know if I have to import it or not and if I have to imported I don´t know how.
How can I use this library in my project?
When we want to invoke native library in Android apps, we can only use dynamic library, which usually ends with .so extension.
So that means you have to build a dynamic library based on .a file.

How do i call C/C++ code from Android using JNA?

I'm trying to integrate this specific library to my Android project, and the library is written in C/C++. I've miraculously gotten ndk-build to give me the needed .so file.
However, looking at it, there's a sample in the project, and they use a mysterious .jar with the API bindings of the .c/c++ files.
How do i either
create this special .jar file that has the API, based on the .so?
OR
directly add a method to the main c++ file and then call it from Java?
I've tried to re-wrap things using JNI, but it definitely doesn't seem to work. i keep getting UnsatisfiedLinkError.
A lot of the documentation online uses jni as the tutorial. i'm happy with just a few links to tutorials on JNA.
JNA provides a stub native library, libjnidispatch.so for a variety of platforms. You can build this library yourself, or extract one of the pre-built binaries from the project's lib/native/<platform>.jar packages.
You include libjnidispatch.so in your Android project the way you would any other JNI library. This is required; you cannot rely on JNA to dynamically unpack and use its native library automatically like on other platforms. The JNA project includes details for doing so (as well as instructions for building libjnidispatch.so yourself).
You then use jna.jar as you would any other Java jar file, and write your own (Java) mappings to match the native library you're trying to access. There's also a jna-min.jar which omits all the native platform libraries that are normally bundled in jna.jar.
Do go to project properties and build paths and remove JNA 4.0 and related classes.
This will work!

How to read DICOM file on android os?

I want to know how to display a DICOM file on the Android OS ? Can I do it?
Some are using DCMTK (http://www.dcmtk.org) on Android via Android NDK to acces DICOM. There's a discussion about it on the DCMTK forums here: http://forum.dcmtk.org/viewtopic.php?t=2960&sid=868791a13b4d266998284b921c4bfe8c
Imebra now includes JNI wrappers for Android and comes with a pre-built jar that includes java classes and so libraries with native code.
It is possible to access the Pixelmed Java DICOM Toolkit on Android, http://www.pixelmed.com . You should be able to use some of its functionality without even recompiling the JAR.

Categories

Resources