0

I am trying to build boringssl for Android's armeabi-v7a. I looked at the boringssl git document and built it.

//termanal
cmake -DANDROID_ABI=armeabi-v7a \
-DANDROID_PLATFORM=android-21 \
-DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_ROOT}/build/cmake/android.toolchain.cmake \
-DBUILD_SHARED_LIBS=1 \
-GNinja -B build

ninja -C build 

When you run the above command in the terminal, the boringssl/build directory is created and .so and build files are created inside the directory.

I put libcrypto.so, libssl.so in app/opensslSO/libs in android project. Header files are placed in app/opensslSO/include.

I wrote CMakeLists.txt for library linking.

cmake_minimum_required(VERSION 3.18.1)


# OpenSSL 라이브러리 경로 설정
set(OPENSSL_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/opensslSO/include")
set(OPENSSL_LIBRARY_DIR "${CMAKE_SOURCE_DIR}/opensslSO/libs")

include_directories(
    ${OPENSSL_INCLUDE_DIR}
)

add_library(crypto SHARED IMPORTED)
set_target_properties(crypto PROPERTIES IMPORTED_LOCATION ${OPENSSL_LIBRARY_DIR}/libcrypto.so)

add_library(ssl SHARED IMPORTED)
set_target_properties(ssl PROPERTIES IMPORTED_LOCATION ${OPENSSL_LIBRARY_DIR}/libssl.so)

add_library(pki SHARED IMPORTED)
set_target_properties(pki PROPERTIES IMPORTED_LOCATION ${OPENSSL_LIBRARY_DIR}/libpki.so)

add_library(decrepit SHARED IMPORTED)
set_target_properties(decrepit PROPERTIES IMPORTED_LOCATION ${OPENSSL_LIBRARY_DIR}/libdecrepit.so)


add_library( score_printer

             # Sets the library as a shared library.
             SHARED

             # Provides a relative path to your source file(s).
             my_native_file_path
             )


target_link_libraries( native_lib
                       crypto
                       ssl
                       pki
                       decrepit
                       android
                       log
                       EGL
                       GLESv1_CM
                      )

I thought it would work fine, but I get an error.

/opensslSO/libs/libcrypto.so: error adding symbols: File in wrong format
  clang++: error: linker command failed with exit code 1 (use -v to see invocation)
  ninja: build stopped: subcommand failed.
2
  • By the looks of it, you're only building BoringSSL for armeabi-v7a. Have you added the necessary abiFilters in your gradle script so that your other native code also is built only for armeabi-v7a? Also, what is native_lib? Did you mean score_printer? Commented Mar 27, 2024 at 10:09
  • Thanks for your reply. I solved the problem and left it in the answer. Commented Mar 28, 2024 at 0:04

1 Answer 1

0

Solved :

This can be solved by building ABI for not only armeabi-v7a, but also arm64-v8a, x86 and x86_64 and setting the directories separately.


set(OPENSSL_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/opensslSO/include")
set(OPENSSL_LIBRARY_DIR "${CMAKE_SOURCE_DIR}/opensslSO/libs/${ANDROID_ABI}")

include_directories(
    ${OPENSSL_INCLUDE_DIR}
)

add_library(crypto SHARED IMPORTED)
set_target_properties(crypto PROPERTIES IMPORTED_LOCATION ${OPENSSL_LIBRARY_DIR}/libcrypto.so)


add_library(ssl SHARED IMPORTED)
set_target_properties(ssl PROPERTIES IMPORTED_LOCATION ${OPENSSL_LIBRARY_DIR}/libssl.so)

add_library(pki SHARED IMPORTED)
set_target_properties(pki PROPERTIES IMPORTED_LOCATION ${OPENSSL_LIBRARY_DIR}/libpki.so)

add_library(decrepit SHARED IMPORTED)
set_target_properties(decrepit PROPERTIES IMPORTED_LOCATION ${OPENSSL_LIBRARY_DIR}/libdecrepit.so)


target_link_libraries( 
                       crypto
                       ssl
                       pki
                       decrepit
                       android
                       log
                       EGL
                       GLESv1_CM
                      )

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.