MAC Android OpenSSL compiled

  • Start by downloading the latest code on Github

    mkdir androidopenssl
    
    cd androidopenssl
    
    git clone https://github.com/openssl/openssl
    Copy the code

    At present, the latest code of Matser is pulled down, which may be unstable. It is recommended to switch to a stable tag

    git tag
    
    git checkout OpenSSL_1_1_1
    
    Copy the code

    I have chosen the OpenSSL_1_1_1 version here

  • Create a build_openSSL_shell. sh file on androidOpenssl and edit it:

    #! /bin/bash set -e set -x SCRIPTPATH=. export ANDROID_NDK_HOME=/Users/dengqu/Downloads/android-ndk-r17c OPENSSL_DIR=$SCRIPTPATH/openssl CC=clang PATH=$ANDROID_NDK_HOME/toolchains/arm-linux-androideabi-4.9/prebuilt/ Darwin x86_64/bin:$PATH It's compiled. Compiling failed when setting 14, ANDROID_API=21 # Set the target library for compilation # Target library options android-arm, Android-arm64, Android-x86 Android-x86 etc architecture=android-arm CD ${OPENSSL_DIR}./Configure ${architecture} -d__android_API__ =$ANDROID_API # Build make # copy to the output directory OUTPUT_INCLUDE=$SCRIPTPATH/output/include OUTPUT_LIB=$SCRIPTPATH/output/lib/${architecture} mkdir -p $OUTPUT_INCLUDE mkdir -p $OUTPUT_LIB cp -RL include/openssl $OUTPUT_INCLUDE cp libcrypto.so $OUTPUT_LIB cp libcrypto.a $OUTPUT_LIB cp libssl.so $OUTPUT_LIB cp libssl.a $OUTPUT_LIBCopy the code
  • Then change the permission to run the build_openSSL_shell. sh script

    chmod a+x build_openssl_shell.sh
    Copy the code
  • The directory structure is as follows:

  • Run the script

       ./build_openssl_shell.sh
    Copy the code

    If all goes well, the output file will be generated in the OpenSSL directory

    Include is the header file. Lib contains dynamic and static libraries, depending on which one you want to use, copy it into your project

  • Problems encountered

    1. The NDK system path could not be found. Procedure

    In this case, you need to check whether the NDK path is configured

    vim ~/.bash_profile  
    Copy the code

    source ~/.bash_profile 
    Copy the code
    1. crypto/ec/ecp_nistz256-armv4.S:9: Error: unknown pseudo-op: `.rodata’

    The solution is to edit the ecp_nistz256-armV4.s file and delete.rodata

    cd androidopenssl/openssl/crypto/ec
    vim ecp_nistz256-armv4.S
    Copy the code

    And then go to rodata, delete it and save it