2

I'm a bit confused with what I'm currently attempting: I want to cross-compile a C library for use with Android through the NDK, so that I can create a JNI wrapper and call some of its functions from my Android java code.

  • I followed this guide to crosscompile libopus (the library I want to include in my project): http://mortoray.com/2012/08/21/android-ndk-cross-compile-setup-libpng-and-freetype/ which means I currently have a standalone toolchain at /opt/android-ext/, with a lib folder that contains the library I cross-compiled (libopus.a, libopus.so, etc).

  • I also already have a jni folder on my Android project, which contains some C code with the JNI bindings that I want, and that I can call from my Java code, but it does nothing (I can call it but it's a blank function). This means that in my project, there's a /lib/armeabi directory with "libopusUtilsNative.so" (the wrapper).

My question is:

How do I add the library that I just crosscompiled to the project, so that (for example) I can just do an #include call on the C source code file that I already have and get access to the library functions? I'm a bit lost with how to:

  1. Include the library I cross-compiled into my project.

  2. How to make the wrapper code I created include it (I'm guessing this has something to do with adding some code to my Android.mk file, but I'm clueless).

1 Answer 1

1

The guide that you linked to contains an example of how to modify the Android.mk file for your JNI library (or in his case, a native app) to link against the cross-compiled library:

PLATFORM_PREFIX := /opt/android-ext/ LOCAL_PATH := $(PLATFORM_PREFIX)/lib include $(CLEAR_VARS) LOCAL_MODULE := libpng LOCAL_SRC_FILES := libpng.a include $(PREBUILT_STATIC_LIBRARY) # The in your project add libpng LOCAL_STATIC_LIBRARIES := android_native_app_glue libpng 

That's pretty much how you'd do it if you wanted to link statically against libopus. Or if you want to link against the shared library, use something like this: Using my own prebuilt shared library in an Android NDK project

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

3 Comments

Yes, however I'm not sure how to add that bit to my already-existing Android.mk. For example, in my Android.mk, the LOCAL_PATH variable is already defined as $(call my-dir). If I just copy-paste it into my existing Android.mk, won't that be an issue?
Well, if you want to you could probably remove that LOCAL_PATH assignment from the above makefile snippet and specify the full path of the lib in LOCAL_SRC_FILES.
It seems to have worked... to a degree. Here's my current issue: stackoverflow.com/questions/14325440/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.