0

I have a shared library in C. I want to compile and run a test application on my android device. As for as my understanding goes, here is what I think I have to do:

  1. Cross compile the library for the arm device using its tool chain
  2. Make an android.mk file and compile using NDK (I followed this link : build-cc-executables-for-android-using-ndk)

I modified the android.mk file to add a shared library,

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS) 
# give module name
LOCAL_MODULE    := depend1
LOCAL_SRC_FILES := libdepend1.so 
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS) 
# give module name
LOCAL_MODULE    := depend2
LOCAL_SRC_FILES := libdepend2.so 
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS) 
# give module name
LOCAL_MODULE    := test
# list your C files to compile
LOCAL_SRC_FILES := test.c
# this option will build executables instead of building library   
include $(BUILD_EXECUTABLE)

The project compiles. I get my executable in the libs folder.

On running the executable on android shell using adb I get the following error:

Init: Error opening /data/local/project/depend1.so:  dlopen failed: could not load library "depend2.so" needed by "depend1.so"; caused by could not load library "libgcc_s.so.1" needed by "depend2.so"; caused by library "libgcc_s.so.1" not found

(NOTE: dlopen is part of my code)

It is not able find a library that is part of the toolchain, I didnt find this library in /system/lib of the device, which leads me to my first question - Am i using the right toolchain (the one I used is arm-none-linux-gnueabi) Secondly am I building it correctly for android?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • Take a look into [this](https://stackoverflow.com/questions/48579189/how-do-i-load-a-native-library-so-from-another-native-library-so) question, you might have an issue with paths. Also why won't you link it as a static lib? – Dmitrii Z. Feb 02 '18 at 15:45
  • The link provides a solution, I'm yet to start the java portion of my project. Will check the paths. I've been provided shared libraries, any advantage if they are static libraries? – Rohith Mohan Feb 03 '18 at 06:29

1 Answers1

0

This library use Cmake or automake?

For Cmake you just need to properly confugure it (how to)

Example: cmake -DANDROID_NDK=path/to/ndk -DCMAKE_TOOLCHAIN_FILE=$NDK/build/cmake/android.toolchain.cmake --DANDROID_ABI=armeabi-v7a -DANDROID_PLATFORM=android-21 ..

For automake you should use prebuilt GCC toolchains (but GCC deprecated in NDK) or create new own standalone toolchain (how to)

This toolchains are 100% valid for cross-compiling for Android

If you still want use ndk-build you can read this link (I don't use it, so I can help further only with Cmake and automake)

  • Hi, I haven't reached the stage where I want to run an apk (nor have I started using Android studio yet). I will try this later on. As of now i just want to execute it on Android Shell. Thanks – Rohith Mohan Feb 03 '18 at 06:25
  • Hi! So, as I said in my answer, you can create CMakeLists.txt for your executable, configure for Android and build. This isn't require Android Studio, something else, just NDK. – Van der Deken Feb 03 '18 at 08:37