3

I have a library in c/c++. I have used it successfully in a few c++ programs.

I want to test if it compiles on Android, and what size it would be etc.
Is there any way for me to compile this library to a .so file without having a whole Android Java project? I know nothing about Android development, but have a friend who wants to use my library. Can I just supply him with a compiled .so file?
Every resource I found says it needs to be compiled out of a JNI folder in an Android Project.

2 Answers 2

4

I discovered that to use the build-ndk script, I don't need a real project. I created a folder project, with nothing in it except another folder jni, and put all my sources in that folder. I then created the Android.mk file and ran the script as described in the ndk docs.

Sign up to request clarification or add additional context in comments.

1 Comment

There's nothing special about the project directory - name it whatever you want. The sources and Android.mk should go in $(project)/jni/, and during the build some directories will be created: $(project)/obj and $(project)/libs.
2

What you will need to do this is the android Native Development Kit (NDK) http://developer.android.com/sdk/ndk/index.html and a GCC compiler.

You can then create a Makefile with the parameters as shown below (thanks ViTo Brothers Apoyan) and create your shared library.

GCC := C:\Tools\ndk-toolchain\ndk-standalone\bin\arm-linux-androideabi-gcc.exe GPP := C:\Tools\ndk-toolchain\ndk-standalone\bin\arm-linux-androideabi-g++.exe AR := C:\Tools\ndk-toolchain\ndk-standalone\bin\arm-linux-androideabi-ar.exe OPTIONS :=\ -fpic \ -ffunction-sections \ -funwind-tables \ -fstack-protector \ -D__ARM_ARCH_5__ \ -D__ARM_ARCH_5T__ \ -D__ARM_ARCH_5E__ \ -D__ARM_ARCH_5TE__ \ -Wno-psabi \ -march=armv5te \ -mtune=xscale \ -msoft-float \ -mthumb \ -Os \ -fomit-frame-pointer \ -fno-strict-aliasing \ -finline-limit=64 \ -DANDROID \ -Wa, \ -O2 \ -DNDEBUG \ -g \ default: all all: obj $(AR) r mysharedlibrary.so *.o obj: $(GCC) $(OPTIONS) -c *.c 

1 Comment

Thanks, but I ended up solving this a simpler way.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.