0

I am having .a file from third-party. How can use it in android studio?

Please help me.

HaveNoDisplayName
  • 8,291
  • 106
  • 37
  • 47
Pradeep
  • 29
  • 3

1 Answers1

1

You can not use directly a .a library in your app. This libraries are static and Android app only allow you to load dynamic libraries.

But you can build a dynamic library linking with your static library. Si you just have to add a few line to you Android.mk to link with this static library. Put your prebuilt .a and his header in a prebuild jni alongside your jni folder. Then your Android.mk should look like something like this :

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE    := YourStaticLib
LOCAL_SRC_FILES := ../prebuilt/your_static_lib_prebuild.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../prebuilt
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)

LOCAL_MODULE    := DynamicLib
LOCAL_C_INCLUDES := $(LOCAL_PATH) \
                $(LOCAL_PATH)/../prebuilt
LOCAL_SRC_FILES := your_src_file.cpp
LOCAL_LDLIBS    := -llog
LOCAL_ARM_NEON  := true

LOCAL_STATIC_LIBRARIES := YourStaticLib

include $(BUILD_SHARED_LIBRARY)
sonic
  • 1,894
  • 1
  • 18
  • 22
  • thanks for the fast response. Here I have small doubt. How to add Android.mk file inside android studio? – Pradeep Jan 05 '16 at 10:28
  • You are welcome. What did you use to build your native code ? – sonic Jan 05 '16 at 10:37
  • Am using "com.android.tools.build:gradle-experimental:0.4.0". Is that any other way to build without Android.mk. Is there is no other ways then pls guide me how to override ndk_build in build.gradle file... – Pradeep Jan 05 '16 at 10:41
  • I don't know how to do this, using only gradle. But you can make gradle using your own Android.mk file. This answer on SO explain how to http://stackoverflow.com/a/27840210/4170584 – sonic Jan 05 '16 at 10:48