I have a large library of C files that relies on OpenSSL and I'm very new to working with native libraries, and especially new to working with android. I've managed to implement this library on iOS with no problems.
I've been looking around online for tutorials / information on how to do this, but so far I haven't found anything I can understand. It's all very confusing to me.
Essentially I'm trying to figure out how to compile the library of C files into a native lib using NDK and use the compiled library with imy android application.
From what I understand, I need a custom cmake file for android itself, but I don't know where to start with that and the documentation I've found has been incredibly difficult to follow.
So, I need some help understanding what the process would be of compiling the library in the following manor:
- Compile the library, linking it with openssl and libcrypto, using Gradle and CMakeLists.txt and link the final library with my Android Studio project.
- Be able to make calls to the native functions within these libraries from my Java code. (I understand that this requires a JNI Java Wrapper)
(I've already managed to build libssl and libcrypto for all archs that android requires, but I'm not sure what to do with the .a
/.so
files.)
Any help on this matter would be incredibly appreciated.
Thanks
EDIT:
I managed to generate some library files with the following.
File Structure:
.idea
app
build
gradle
jni <--- I made this folder specifically fo this.
Android.mk <-- This is the important file.
include
openssl
<openssl header files>
libs
arm64-v8a
libcrypto.a
libcrypto.so
libssl.a
libssl.so
armeabi
libcrypto.a
libcrypto.so
libssl.a
libssl.so
armeabi--v7a
libcrypto.a
libcrypto.so
libssl.a
libssl.so
mips
libcrypto.a
libcrypto.so
libssl.a
libssl.so
mips64
libcrypto.a
libcrypto.so
libssl.a
libssl.so
x86
libcrypto.a
libcrypto.so
libssl.a
libssl.so
x86_64
libcrypto.a
libcrypto.so
libssl.a
libssl.so
src <--- These are example files that i used to build this with.
myc_files.c
myother_c_files.c
myc_heades.h
myother_c_headers.h
I then used the following in the Android.mk to generate some libraries by running ndk-build
.
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
# Select from arm64-v8a armeabi armeabi-v7a mips mips64 x86 x86_64
ARCH := armeabi
APP_UNIFIED_HEADERS := true
#APP_ABI := $(ARCH)
# TARGET_ARCH := $(ARCH)
TARGET_PLATFORM := android-14
SRC_DIR := $(LOCAL_PATH)/src
HDR_DIR := $(LOCAL_PATH)/include
LIB_DIR := $(LOCAL_PATH)/libs
LOCAL_C_INCLUDES := $(HDR_DIR)
LOCAL_MODULE := myclib
LOCAL_SRC_FILES := $(SRC_DIR)/myc_files.c $(SRC_DIR)/myother_c_files.c
LOCAL_LDLIBS += -L$(LIB_DIR)/$(ARCH) -lssl -lcrypto
include $(BUILD_STATIC_LIBRARY)
The libraries were put into PROJECT/obj/local
and I have no idea where to go from here, or if that Android.mk file actually properly built the libraries.