8

I'm building an Android apk who uses some native libraries of a third party, these libs are in Static Object Code Library (.a files) and I need to write a JNI wrapper to access in Java these functions.

Those libs are already compiled with a cross-compiler and are natively to Android.

How do I compile my JNI sources linking to the functions in the .a libs files?

This is my Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_LDLIBS := -llog

LOCAL_MODULE    := ndk1
LOCAL_SRC_FILES := native.c

include $(BUILD_SHARED_LIBRARY)

When I compile, I get only the native.c file compiled.

Marcos Vasconcelos
  • 18,136
  • 30
  • 106
  • 167

2 Answers2

11

To do that.

I have to declare these libs as modules. Like the following.

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE    := curl
LOCAL_SRC_FILES := libcurl.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include

include $(PREBUILT_STATIC_LIBRARY)

With a libcurl.a file in the same folder as this Android.mk file, and a /include fodler with the headers.

Now in the main module just declare the lib and the Android NDK will take care of the rest.

LOCAL_PATH := $(call my-dir)

include $(call all-subdir-makefiles)
include $(CLEAR_VARS)

LOCAL_LDLIBS := -llog -ldl
LOCAL_MODULE    := rmsdk
LOCAL_SRC_FILES := curlnetprovider.cpp native.c
LOCAL_STATIC_LIBRARIES := curl

include $(BUILD_SHARED_LIBRARY)

Note.. you should include the Android.mk file of the module before using it. I do that with the call all-subdir-makefiles.

Marcos Vasconcelos
  • 18,136
  • 30
  • 106
  • 167
  • 2
    Also works with shared libraries (*.so). For example I just "adb pull /system/lib/libsqlite.so" to link against sqlite. – Philippe Girolami Jan 17 '11 at 13:03
  • I try different ways but I cant find answer please help http://stackoverflow.com/questions/7332679/cant-create-shared-library-with-static-inside – Viktor Apoyan Sep 08 '11 at 12:04
  • @Marcos the first is a separate makefile?? if so where you have to add it and i dont see anylink to the first makefile in the second part?? – jxgn Sep 26 '12 at 04:31
1

Your libs have to be compiled for your specific target (Arm), to do that I think you have to use the toolchain as described in docs/STANDALONE-TOOLCHAIN.html (in your ndk-r5 folder).

thbusch
  • 550
  • 2
  • 10