Cross-compile the AVS Device SDK for iOS

The following step-by-step instructions teach you how to cross-compile and build the AVS Device SDK for iOS. If you encounter any errors or have questions, browse the SDK issue list before creating a new issue.

Warning

The AVS Device SDK sample app does not run on iOS. This guide doesn't walk through the cross-compilation of all required dependencies to launch the SDK on iOS.

After cross-compiling the SDK, you must create a custom iOS app to wrap the native AVS Device SDK code. This development requires you to integrate SDK features on your own – microphone, speaker, media player and more.

Prerequisites

Confirm that you have installed curl, Homebrew, and Xcode command line tools.

curl --version
brew --version
xcode-select --version

Install dependencies

  1. Install the required dependencies.

    brew install cmake pkg-config
    
  2. Create a build folder for your project.

    cd ~
    mkdir cross-compile
    cd cross-compile
    
  3. Clone CMake for iOS into your build folder.

    cd ~/cross-compile
    git clone https://github.com/leetal/ios-cmake.git
    
  4. Download and cross-compile Google Test.

    cd ~/cross-compile
    git clone https://github.com/google/googletest.git
    mkdir googletest_build
    
    cd googletest_build
    
    cmake ../googletest \
    -DIOS_DEPLOYMENT_TARGET=10.0 \
    -DCMAKE_TOOLCHAIN_FILE=../ios-cmake/ios.toolchain.cmake \
    -DIOS_PLATFORM=OS \
    
    make
    
  5. Download and cross-compile OpenSSL and curl. Clone the repository from GitHub.

    cd ~/cross-compile
    git clone https://github.com/jasonacox/Build-OpenSSL-cURL.git
    cd Build-OpenSSL-cURL/
    
  6. Open build.sh and change the curl version to 7.55.1.

    ########################################
    # EDIT this section to Select Versions #
    ########################################
    
    OPENSSL="1.0.2l"
    LIBCURL="7.55.1"
    NGHTTP2="1.24.0"
    
    ########################################
    
  7. Save the file.
  8. Run the script.

    ./build.sh
    

Download the SDK and configure the SDK

  1. Clone the AVS Device SDK.

      cd ~/cross-compile
      git clone https://github.com/alexa/avs-device-sdk.git  
      cd avs-device-sdk/
    
  2. Replace the source code in /AVSCommon/Utils/src/LibcurlUtils/LibcurlUtils.cpp

    • Find this code

       if (config.getString(CAPATH_CONFIG_KEY, &caPath) &&
           !setopt(handle, CURLOPT_CAPATH, caPath.c_str(), "CURLOPT_CAPATH", caPath.c_str())) {
           return false;
       }
      
    • Replace it with this code

       if (config.getString(CAPATH_CONFIG_KEY, &caPath) &&
       !setopt(handle, CURLOPT_CAINFO, caPath.c_str(), "CURLOPT_CAINFO", caPath.c_str()) &&
       !setopt(handle, CURLOPT_CAPATH, caPath.c_str(), "CURLOPT_CAPATH", caPath.c_str())) {
       return false;
       }
      
  3. The SDK must run as a STATIC library. You must make it global in all subfolders.

      cd ~/cross-compile/avs-device-sdk/
      find . -type f -name '*.txt' -exec sed -i '' s/SHARED/STATIC/ {} +
    

Build the SDK

Build the SDK with the following CMake parameters:

 cd ~/cross-compile
 mkdir avs_build

 cd avs_build

 cmake ../avs-device-sdk
 -DIOS_DEPLOYMENT_TARGET=10.0 \
 -DCMAKE_TOOLCHAIN_FILE=../ios-cmake/ios.toolchain.cmake \
 -DIOS_PLATFORM=OS \
 -DGSTREAMER_MEDIA_PLAYER=OFF \
 -DCURL_LIBRARY=../Build-OpenSSL-cURL/archive/libcurl-7.54.1-openssl-1.0.2l-nghttp2-1.24.0/libcurl_iOS.a \
 -DCURL_INCLUDE_DIR=../Build-OpenSSL-cURL/curl/curl-7.55.1/include \
 -DGTEST_LIBRARY=../googletest_build/googlemock/libgmock.a \
 -DGTEST_MAIN_LIBRARY=../googletest_build/googlemock/libgmock_main.a \
 -DGTEST_INCLUDE_DIR=../googletest/googletest/include/ \
 -DPKG_CONFIG_EXECUTABLE=/usr/local/bin/pkg-config

OPTIONAL: Build with the ability to run in the iOS simulator

 cd ~/cross-compile

 mkdir avs_build_sim
 cd avs_build_sim

 cmake ../avs-device-sdk
 -DIOS_DEPLOYMENT_TARGET=10.0 \
 -DCMAKE_TOOLCHAIN_FILE=../ios-cmake/ios.toolchain.cmake \
 -DIOS_PLATFORM=SIMULATOR64 \
 -DGSTREAMER_MEDIA_PLAYER=OFF \
 -DCURL_LIBRARY=../Build-OpenSSL-cURL/archive/libcurl-7.54.1-openssl-1.0.2l-nghttp2-1.24.0/libcurl_iOS.a \
 -DCURL_INCLUDE_DIR=../Build-OpenSSL-cURL/curl/curl-7.55.1/include \
 -DGTEST_LIBRARY=../googletest_build/googlemock/libgmock.a \
 -DGTEST_MAIN_LIBRARY=../googletest_build/googlemock/libgmock_main.a \
 -DGTEST_INCLUDE_DIR=../googletest/googletest/include/ \
 -DPKG_CONFIG_EXECUTABLE=/usr/local/bin/pkg-config

To build what's required for the iOS proof of concept run these commands

 make CBLAuthDelegate
 make DefaultClient
 make KWD
 make PlaylistParser

Make sure that each make command reaches 100%.