简体   繁体   English

如何在项目android中加载两个预构建库的.so文件?

[英]How to load .so files of two pre built libraries in project android?

I have two projects .so files. 我有两个项目.so文件。 project one contains prebuilt openssl .so files build using CMake. 项目一包含使用CMake构建的预建openssl .so文件。 and second projects contains some .so files which is build using Android.mk. 第二个项目包含一些使用Android.mk构建的.so文件。 Now My problem is i want to use both projects in my new project. 现在我的问题是我想在我的新项目中同时使用两个项目。 but i am not getting how to write CMake or Android.mk. 但我不知道如何编写CMake或Android.mk。

here is code of CMake of first project 这是第一个项目的CMake代码

# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html

# Sets the minimum version of CMake required to build the native library.

cmake_minimum_required(VERSION 3.4.1)

# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.

add_library( # Sets the name of the library.
             native-lib

             # Sets the library as a shared library.
             SHARED

             # Provides a relative path to your source file(s).
             src/main/cpp/native-lib.cpp )


             add_library(openssl SHARED IMPORTED)
             set_target_properties (openssl PROPERTIES IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/lib/libcrypto.so )

             add_library(prebuilt_ssl SHARED IMPORTED)
             set_target_properties (prebuilt_ssl PROPERTIES IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/lib/libssl.so )






# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.

include_directories(openssl-armeabi-v7a/include/)
find_library( # Sets the name of the path variable.
              log-lib

              # Specifies the name of the NDK library that
              # you want CMake to locate.
              log )

# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.

target_link_libraries( # Specifies the target library.
                       native-lib
                      ${CMAKE_CURRENT_SOURCE_DIR}/openssl-armeabi-v7a/lib/libcrypto.a
                      ${CMAKE_CURRENT_SOURCE_DIR}/openssl-armeabi-v7a/lib/libssl.a

                       # Links the target library to the log library
                       # included in the NDK.
                       ${log-lib} )

and Android.mk of second project 和第二个项目的Android.mk

#
# Copyright 2009 Cedric Priscal
# 
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# 
# http://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License. 
#

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

TARGET_PLATFORM := android-3
LOCAL_MODULE    := serial_port
LOCAL_SRC_FILES := SerialPort.c
LOCAL_LDLIBS    := -llog
include $(BUILD_SHARED_LIBRARY)

Please help me for writing CMake or Android.mk? 请帮我编写CMake或Android.mk吗? which is easy CMake or Android.mk ? 哪个容易CMake或Android.mk?

Google seems to encourage us to use CMake more these days. 最近,Google似乎鼓励我们更多地使用CMake For simple builds, like your libserial_port.so , translation from Android.mk to CMakeLists.txt is not hard: 对于简单的构建(例如您的libserial_port.so) ,将Android.mk转换为CMakeLists.txt并不困难:

add_library(serial_port SHARED SerialPort.c)
target_link_libraries(serial_port log)

(remember, you don't need find_library for log ). (请记住,您不需要find_library记录日志 )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM