Sei sulla pagina 1di 2

How to compile Porting Layer C code for Android

client

Overview
On Android, the client reference code provides a JNI layer above the Java DIL and PL
implementation, but most of the client's PLs are not implemented on Java and require .c code to be
compiled into the dynamically linked library. This can be achieved by using Android.mk file which
comes with Android client delivery.

Solution
In order to compile PL from C code for Android, one should do as follows:
1. Download and Install Android NDK : https://developer.android.com/ndk/downloads
2. Add path to "ndk-build.cmd" file into you system environment variables (example
"D:\Android\sdk\ndk-bundle")
3. Get the PL .c file and all its dependent header files from the relevant VDM branch.
Note: make sure that all preprocessor directives like "#ifdef" are resolved (if any).
4. Copy .c file into your_android_delivery/sdk/source/
5. Copy all headers into your_android_delivery/sdk/import/
6. Go to your_android_delivery/redbend/src/main/ directory.
This dir. will consider to be our “Root” directory, from which we want to compile.
7. Enter “cd jni”. This directory holds two important files, which we will use to compile our libsmm.so
file: Android.mk, Application.mk. Android.mk is in fact, the makefile that builds libsmm.so file.
We will adjust this file a bit, to suite our needs and work properly:
8. Delete the following lines (if exist):
ifeq ($(SSL_LIBRARIES), ../../../../external/lib/libssl_1_1.so ../../../../external/lib/libcrypto_1_1.so)
LOCAL_LDFLAGS += -lssl_1_1 -lcrypto_1_1
else
LOCAL_LDFLAGS += -lssl -lcrypto
endif
9. Delete -lssl and -lcrypto from LOCAL_LDLIBS parameter
10. Add libssl and libcrypto modules to LOCAL_WHOLE_STATIC_LIBRARIES := libssl libcrypto
libswmcinstallers libvdmswmcplcrypt …
11. Add the following lines:
include $(CLEAR_VARS)
LOCAL_MODULE := libssl
LOCAL_SRC_FILES := ../../../../external/lib/libssl_1_1.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libcrypto
LOCAL_SRC_FILES := ../../../../external/lib/libcrypto_1_1.so
include $(PREBUILT_SHARED_LIBRARY)

12. Up until now, we used only static libraries. In order to add a PL .c file that we changed and we
want to compile it into the libsmm.so, we add the following: (example)

include $(CLEAR_VARS)
LOCAL_MODULE := vdm_my_pl
LOCAL_C_INCLUDES := ../../../sdk/include ../../../sdk/import ../../../sdk/import/jni
LOCAL_SRC_FILES := ../../../../sdk/source/your_pl_c_file.c
include $(BUILD_STATIC_LIBRARY)
In the final build of our desired shared library, we add at the beginning, our new static library that we
have just created.
For example:
LOCAL_WHOLE_STATIC_LIBRARIES := vdm_my_pl libssl libcrypto libswmcinstallers
libvdmswmcplcrypt …

13. Go to your_android_delivery/redbend/src/main/ and type: ndk-build, a new smm library will be


complied.

Potrebbero piacerti anche