简体   繁体   中英

Android native project referencing shared library from c++ library project

I have 2 projects:

1 - Android Native project
2 - C/C++ Project

I'm building my shared library files (.so) in a C/C++ project and want to use those .so files in Android Native project. I don't want to copy and paste these library files from one project to another.

First of all is it possible to use those .so files from my native Android project by using some reference etc to C++ library project?

Would it be easier to find a way to automatically copy the .so files from the C++ library project to the Android native project?

Well you'll need to re-compile your libs for ARM first. You can use the ndk's "standalone toolchain" functionality for that. There's a doc explaining more about it in the ndk dir (docs/STANDALONE-TOOLCHAIN.html). I needed to use libexpat in a project so I whipped up a bash file to compile expat using the standalone toolchain like so:

NDK_PATH=/android-ndk-r7
NDK_GCC=${NDK_PATH}/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc

export CC="${NDK_GCC} --sysroot=${NDK_PATH}/platforms/android-8/arch-arm"
export CFLAGS='-mthumb'
export LDFLAGS='-Wl,--fix-cortex-a8'
./configure --host=arm-eabi
make

Then you can copy the so wherever you want and reference it from Android.mk:

LOCAL_LDLIBS := \
-Lvendor/expat/sdk/lib/android \
-lexpat

Note that I built expat and linked it statically so I didn't have to worry about copying the resulting so

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