亞馬遜Alexa Auto SDK示例SampleApp的整合開發
從這個月十號起亞馬遜關於車載語音的開源專案Alexa Auto SDK正式在Github推出,其中Alexa Auto SDK引擎、 核心模組、Alexa模組、導航模組、手機控制模組五大模組幾近涵蓋了車載導航方面的所有功能示例。
一、整體模組的功能:
Alexa Auto SDK包含將Alexa整合到汽車中所需的基本客戶端軟體。Alexa Auto SDK提供了一個用於與Alexa服務通訊的執行時引擎。它還提供允許開發人員實現平臺特定行為的介面,例如音訊輸入,媒體播放,模板和狀態渲染以及電話控制。它還包括一個示例應用程式,演示如何使用Alexa Auto SDK介面。
二、接入示例的演示:
三、接入Alexa Auto SDK的samples流程:
1、註冊產品:
這一步就是在Amazon開發者平臺上建立一些安全配置檔案、產品ID、客戶端ID及api_key.txt等必要的配置資訊,然後填充到示例app或者自己的App當中去。這方面就不贅述在我的部落格亞馬遜語言識別Alexa之AlexaAndroid的接入及AlexaAndroid的原始碼解析(一)中的前半部分的註冊流程基本一致。
2、Include Alexa Auto SDK dependencies(Alexa Auto SDK 的依賴編譯):
在這一步驟中特別要注意Alexa Auto SDK Builder的話有兩種方式都可以實現依賴編譯,
3.如上Alexa Auto SDK Builder編譯成功之後拷貝出項目AAC-SDK,我是在自己開發的window平臺中用Android Studio去開啟該專案。
注:可能在window平臺上會出現我所遇到過得問題,接下來是我解決這一問題思路,僅供大家參考少去踩重複的坑:
1)、上面2中編譯成功後的SDK,來到window平臺下的Android Studio下會出現CMakeLists.txt編譯不過
Error:A problem occurred configuring project ':aace'.
> executing external native build for cmake E:\alexaauto\aac-sdk\platforms\android\aace\CMakeLists.txt
在CMakeList.txt中報錯的具體行為:
if (NOT ${PREP_RESULT} EQUAL 0)
message(FATAL_ERROR "Script execution failed") //這裡報錯說明prepare-native-dependencies.sh的指令碼執行的不成功
endif()
2)、從1)中找到源頭說明是執行指令碼prepare-native-dependencies.sh沒有執行成功:
execute_process(
//${CMAKE_CURRENT_SOURCE_DIR}代表當前目錄,執行.sh,${ANDROID_ABI}是傳入.sh中引數${1},${ANDROID_PLATFORM}是引數${2}
COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/prepare-native-dependencies.sh" ${ANDROID_ABI} ${ANDROID_PLATFORM}
RESULT_VARIABLE PREP_RESULT
)
轉到prepare-native-dependencies.sh的指令碼檔案進行分析:
#!/bin/bash
set -e
THIS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SDK_HOME=${THIS_DIR}/../../..
BUILDER_HOME=${SDK_HOME}/builder
DEPLOY_DIR=${THIS_DIR}/native-dependencies
# Extra options
ANDROID_ABI=${1} //從CMakeLists.txt傳入的${ANDROID_ABI}
ANDROID_PLATFORM=${2} //從CMakeLists.txt傳入的${ANDROID_PLATFORM}
if [ -z ${ANDROID_ABI} ] || [ -z ${ANDROID_PLATFORM} ]; then
echo "Please specify ABI/API"
exit 1
fi
mkdir -p ${DEPLOY_DIR}
//找到builer/deploy/androidarm下的aac-image-minimal-armeabi-v7a-android-22.tar.gz
//aac-image-minimal-armeabi-v7a-android-22.tar.gz即是"aac-image-minimal-${ANDROID_ABI}-${ANDROID_PLATFORM}.tar.gz"
IMAGE_NAME="aac-image-minimal-${ANDROID_ABI}-${ANDROID_PLATFORM}.tar.gz"
find ${BUILDER_HOME}/deploy \
-name ${IMAGE_NAME} \
-exec cp {} ${DEPLOY_DIR} \;
if [ ! -e ${DEPLOY_DIR}/${IMAGE_NAME} ]; then
echo "AAC Build for ${ANDROID_ABI}/${ANDROID_PLATFORM} is not found!"
exit 1
fi
SYSROOT="${DEPLOY_DIR}/sysroots/${ANDROID_ABI}"
mkdir -p ${SYSROOT} && tar xf ${DEPLOY_DIR}/${IMAGE_NAME} -C ${SYSROOT}
JNI_DEPLOY="${DEPLOY_DIR}/jni/${ANDROID_ABI}"
mkdir -p ${JNI_DEPLOY} //建立一個/native-dependencies/jni/${ANDROID_ABI}的檔案加
find ${SYSROOT}/opt/AAC/lib -name "*.so" -exec cp {} ${JNI_DEPLOY} \;
3)、把prepare-native-dependencies.sh指令碼資訊修改為在Ubuntu下編成的專案下的builder->deploy->androidarm->aac-image-minimal-armeabi-v7a-android-22.tar.gz:
把prepare-native-dependencies.sh中的${1}、${2}改為對應的armabi-v7a、android-22:
DEPLOY_DIR=${THIS_DIR}/native-dependencies
# Extra options
ANDROID_ABI=armeabi-v7a
ANDROID_PLATFORM=android-22
4)、回到報錯的CMakeLists.txt中其實2)的執行cmake的exectue_process就是為了執行prepare-native-dependencies.sh指令碼從而實現腳本里的建立和生成native-dependencies檔案和裡面的so庫。如現在手動點選3)所修改的prepare-native-dependencies.sh就會對應生成native-dependencies。
5)、有了native-dependencies檔案,接下來就可以把2)中的執行語句exectue_process和1)判斷語句刪除,可以把CMakeLists.txt改為如下:
cmake_minimum_required(VERSION 3.4.1)
set(CMAKE_CXX_STANDARD 11)
message(${CMAKE_CURRENT_SOURCE_DIR}) //打印出${CMAKE_CURRENT_SOURCE_DIR}的值
message(${ANDROID_ABI}) //打印出(${ANDROID_ABI})的值
message(${ANDROID_PLATFORM})
set(MAKE_CMD "${CMAKE_CURRENT_SOURCE_DIR}/prepare-native-dependencies-bake.sh")
message("COMMAND: ${MAKE_CMD}")
set(AAC_HOME ${CMAKE_CURRENT_SOURCE_DIR}/native-dependencies/sysroots/${ANDROID_ABI}/opt/AAC)
if(NOT EXISTS ${AAC_HOME})
message("AAC build for ${ANDROID_ABI}/${ANDROID_PLATFORM} is not exists!")
endif()
message("AAC_HOME的地址為:")
message(${AAC_HOME})
include(${AAC_HOME}/share/cmake/AACECore.cmake)
include(${AAC_HOME}/share/cmake/AACEAlexa.cmake)
include(${AAC_HOME}/share/cmake/AACENavigation.cmake)
include(${AAC_HOME}/share/cmake/AACEPhoneControl.cmake)
add_library(aace-lib SHARED //執行cmake後會生成以aace-lib為名字的so庫
src/main/cpp/src/aace/alexa/AlertsBinder.cpp
src/main/cpp/src/aace/alexa/AlexaClientBinder.cpp
src/main/cpp/src/aace/alexa/AudioPlayerBinder.cpp
src/main/cpp/src/aace/alexa/AuthProviderBinder.cpp
src/main/cpp/src/aace/alexa/MediaPlayerBinder.cpp
src/main/cpp/src/aace/alexa/NotificationsBinder.cpp
src/main/cpp/src/aace/alexa/PlaybackControllerBinder.cpp
src/main/cpp/src/aace/alexa/SpeakerBinder.cpp
src/main/cpp/src/aace/alexa/SpeechRecognizerBinder.cpp
src/main/cpp/src/aace/alexa/SpeechSynthesizerBinder.cpp
src/main/cpp/src/aace/alexa/TemplateRuntimeBinder.cpp
src/main/cpp/src/aace/core/EngineBinder.cpp
src/main/cpp/src/aace/core/PlatformInterfaceBinder.cpp
src/main/cpp/src/aace/location/LocationProviderBinder.cpp
src/main/cpp/src/aace/logger/LoggerBinder.cpp
src/main/cpp/src/aace/navigation/NavigationBinder.cpp
src/main/cpp/src/aace/phonecontrol/PhoneCallControllerBinder.cpp
src/main/cpp/src/aace/network/NetworkInfoProviderBinder.cpp
src/main/cpp/src/NativeLib.cpp
)
target_include_directories(aace-lib PUBLIC src/main/cpp/include)
find_library(android-lib android)
find_library(log-lib log)
target_link_libraries(aace-lib
AACEPhoneControlPlatform AACEPhoneControlEngine
AACENavigationPlatform AACENavigationEngine
AACEAlexaPlatform AACEAlexaEngine
AACECorePlatform AACECoreEngine
${android-lib}
${log-lib}
)
6)、以上就是分析整個過程、要能執行Alexa Auto SDK的sampleApp還需最後一步在acce.gradle下把delete ‘native-depenencies’註釋掉:
//clean.doFirst {
// delete 'native-dependencies'
//}
確保AS Rebuild Project專案中的native-dependencie檔案在手動執行修改後的prepare-native-dependencies.sh是存在的。這樣就能打包手機上執行。
上面示例完成執行之後,接下里就是在Alexa Auto SDK的基礎上去深入的開發自己車載相關的產品咯。