NDK开发 - 使用GMSSL库和OpenSSL库的注意点及编译

2019-08-05  本文已影响0人  Devil_Chen

前言

编译

一、OpenSSL编译

1、参考https://github.com/leenjewel/openssl_for_ios_and_android
2、使用NDK 14来编译。
3、32位的库可以使用Android 16来编译。
4、64位的库必须使用大于等于Android 21来编译。
5、不同OpenSSL版本,头文件可能不同。
PS:使用上面链接下载的脚本可在_shared.sh中修改Android API版本,在build-openssl4Android.sh中可以填写OpenSSL版本。

二、GMSSL编译

1、参考https://github.com/wangp8895/gmssl-for-android
2、使用NDK 14来编译。
3、32位的库可以使用Android 16来编译。
4、64位的库必须使用大于等于Android 21来编译。
5、不同GMSSL版本,头文件可能不同。
PS:使用上面链接下载的脚本可在_shared.sh中修改Android API版本,在build-openssl4Android.sh中可以填写GMSSL版本。

使用

1、Android Studio 3.1.2
2、NDK 16
3、minSDKVersion 16 编译32位。
4、minSDKVersion 21 编译64位。
5、使用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)

#设置JNI变量名的值为${PROJECT_SOURCE_DIR}/src/main/jni
#Mac
set(JNI /${PROJECT_SOURCE_DIR}/src/main/jni)
#windows
#set(JNI ${PROJECT_SOURCE_DIR}/src/main/jni)

# 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.
             nativeLib

             # Sets the library as a shared library.
             SHARED

             # Provides a relative path to your source file(s).
             src/main/jni/nativeTest.cpp)

#静态方式加载
add_library(crypto STATIC IMPORTED )
#配置加载头文件
include_directories( ${JNI}/include)
#引入第三方.a库
set_target_properties(crypto PROPERTIES IMPORTED_LOCATION ${JNI}/libs/${ANDROID_ABI}/libcrypto.a)



# 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.

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.
                       nativeLib
                       crypto
                        -lz

                       # Links the target library to the log library
                       # included in the NDK.

                       ${log-lib})

image.png
上一篇 下一篇

猜你喜欢

热点阅读