简体   繁体   中英

Compile library for Android NDK

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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM