0

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!

tmighty
  • 10,734
  • 21
  • 104
  • 218

1 Answers1

3

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.

KompjoeFriek
  • 3,572
  • 1
  • 22
  • 35
  • Do you think I should port my library to Java entirely and use Android Studio, or should I use NDK if I need the highest speed for my calculation? – tmighty May 25 '15 at 15:20
  • 1
    This really depends on the type of calculations. If your library does very heavy calculations, or if you really need the speed of native code, the best option is to keep it as a native library (compiled with the __Android NDK__). Please note that a native library should be compiled for each Android hardware target you want your __APK__ to run on. (eg: __ARM__, __ARMv7a__ and __x86__). In your `Application.mk` file you should have something like: `APP_ABI := armeabi armeabi-v7a x86` – KompjoeFriek May 25 '15 at 18:54
  • Yes, I really need it to be absolutely high speed. Is it a valid option to use the NDK within Android Studio? I was afraid that the NDK is a command line tool only without any real way to debug / test anything. – tmighty May 26 '15 at 04:27
  • 1
    The NDK is not officially supported by Android Studio yet, but they are working on it and it looks nearly finished, [see here](http://stackoverflow.com/a/27737154/3931225). Debugging the native library [might also be possible](https://github.com/mapbox/mapbox-gl-native/wiki/Android-debugging-with-remote-GDB). – KompjoeFriek May 26 '15 at 09:38