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可以看到如下显示结果:




  • 2017-04-16 21:02:55

    ImageView的android:adjustViewBounds属性

    取值为true时: Adjust the ImageView's bounds to preserve the aspect ration of its drawable. 调整ImageView的界限来保持图像纵横比不变。 这并不意味着ImageView的纵横比就一定和图像的纵横比相同

  • 2017-04-18 17:12:50

    Laravel 读取 config 下的数据

    Laravel的config下一般存放配置信息,可以通过config('key')方法获取指定的数据。 设置值可通过「点」式语法读取,其中包含要访问的文件名以及选项名称。

  • 2017-04-26 16:43:03

    php对象和数组相互转换的方法

    这篇文章主要介绍了php对象和数组相互转换的方法,通过两个自定义函数实现对象与数组的相互转换功能,非常简单实用,需要的朋友可以参考下

  • 2017-04-26 22:59:15

    百度编辑器Ueditor的黑白名单过滤

    黑白名单配置。UEditor针对进入编辑器的富文本内容提供了节点级别的过滤,可以通过该配置的修改来达到控制富文本内容的目的

  • 2017-04-26 23:30:58

    PHP中session变量的销毁

    本篇文章主要是对PHP中session变量的销毁进行了介绍,需要的朋友可以过来参考下,希望对大家有所帮助