Android下openssl编译和使用(二)

2019-08-30 21:59:20

接下来我们看看如何使用


1、新建一个测试工程,并勾选include C++ support


2、把openssl-1.1.1b/include下的openssl目录,整个复制到项目src下的cpp子目录


3、把lib下的libcryto.a和libssl.a复制到src/cpp/libs子目录




4、修改CMakeList.txt文件,在cmake_minimum_required(VERSION 3.4.1)后面添加:


#表示把src/main/cpp加入到include目录,这样在代码中使用:#include <...>就能访问到头文件

include_directories(src/main/cpp)

 

#添加两个预编译库

add_library(# Sets the name of the library.

        openssl-crypto

        # Sets the library as a static library.

        STATIC

        IMPORTED)

 

set_target_properties(

        # Specifies the target library.

        openssl-crypto

        # Specifies the parameter you want to define.

        PROPERTIES IMPORTED_LOCATION

        # Provides the path to the library you want to import.

        ${CMAKE_SOURCE_DIR}/src/main/cpp/libs/${ANDROID_ABI}/libcrypto.a)

 

add_library(# Sets the name of the library.

        openssl-ssl

        # Sets the library as a static library.

        STATIC

        IMPORTED)

 

set_target_properties(

        # Specifies the target library.

        openssl-ssl

        # Specifies the parameter you want to define.

        PROPERTIES IMPORTED_LOCATION

        # Provides the path to the library you want to import.

        ${CMAKE_SOURCE_DIR}/src/main/cpp/libs/${ANDROID_ABI}/libssl.a)

5、修改CMakeList.txt文件最后的target_link_libraries如下:


target_link_libraries( # Specifies the target library.

        native-lib

 

        # Links the target library to the log library

        # included in the NDK.

        ${log-lib} openssl-ssl openssl-crypto)

6、修改native-lib.cpp返回openssl版本信息




7、启动app可以看到如下显示结果:




  • 2020-04-28 10:47:16

    currentColor css 的使用

    以前我们在如何动态设置伪元素的颜色上非过不少心思,看完下面的文章,你就会超级见到那的设置伪元素的颜色了。

  • 2020-04-28 10:48:39

    使用currentColor设置SVG样式

    css自己也又很多变量哦,大家还要多多学习哦。CSS中的变量很有用,因为它们允许我们写更多DRY(不再自我重复,也就是不需要一直写重复内容的代码)代码。它们对于管理和维护大型项目也有非常好用,因为它们包含了大量重复的值。

  • 2020-04-29 20:57:07

    mac卸载avast

    第一种就是卸载。打开主界面,在左上角Avast一栏中选择卸载。卸载完之后要么再装回去,要么去找找别的杀软吧

  • 2020-05-06 14:43:53

    bootstrap @media尺寸

    超大屏,1100分辨率,880分辨率,720分辨率,440分辨率以下