在Android9下用ndk编译vSomeIP和CommonAPI以及使用例子
使用Android NDK编译Boost:
$ cd Boost-for-Android/
修改成需要的版本:
$ vi build-android.sh
BOOST_VER2=70
$ export NDK_ROOT=/AndroidSDK/ndk-bundle
$ nohup ./build-android.sh /AndroidSDK/ndk-bundle &
生成位置:
$ ls build/out/arm64-v8a/*
include:
boost-1_70
lib:
cmake libboost_fiber-clang-mt-a64-1_70.a libboost_math_tr1-clang-mt-a64-1_70.a libboost_stacktrace_noop-clang-mt-a64-1_70.a
libboost_atomic-clang-mt-a64-1_70.a libboost_filesystem-clang-mt-a64-1_70.a libboost_math_tr1f-clang-mt-a64-1_70.a libboost_system-clang-mt-a64-1_70.a
libboost_chrono-clang-mt-a64-1_70.a libboost_graph-clang-mt-a64-1_70.a libboost_math_tr1l-clang-mt-a64-1_70.a libboost_test_exec_monitor-clang-mt-a64-1_70.a
libboost_container-clang-mt-a64-1_70.a libboost_iostreams-clang-mt-a64-1_70.a libboost_prg_exec_monitor-clang-mt-a64-1_70.a libboost_thread-clang-mt-a64-1_70.a
libboost_context-clang-mt-a64-1_70.a libboost_log-clang-mt-a64-1_70.a libboost_program_options-clang-mt-a64-1_70.a libboost_timer-clang-mt-a64-1_70.a
libboost_contract-clang-mt-a64-1_70.a libboost_log_setup-clang-mt-a64-1_70.a libboost_random-clang-mt-a64-1_70.a libboost_type_erasure-clang-mt-a64-1_70.a
libboost_coroutine-clang-mt-a64-1_70.a libboost_math_c99-clang-mt-a64-1_70.a libboost_regex-clang-mt-a64-1_70.a libboost_unit_test_framework-clang-mt-a64-1_70.a
libboost_date_time-clang-mt-a64-1_70.a libboost_math_c99f-clang-mt-a64-1_70.a libboost_serialization-clang-mt-a64-1_70.a libboost_wave-clang-mt-a64-1_70.a
libboost_exception-clang-mt-a64-1_70.a libboost_math_c99l-clang-mt-a64-1_70.a libboost_stacktrace_basic-clang-mt-a64-1_70.a libboost_wserialization-clang-mt-a64-1_70.a
使用Android NDK编译vsomeip的bind库(ENABLE_COMPAT表示兼容老的叫vsomeip,新的叫someip3):
$ mv 3.1.7.1.tar.gz vsomeip-3.1.7.1.tar.gz
$ tar -zxvf vsomeip-3.1.7.1.tar.gz
$ cd vsomeip-3.1.7.1/
$ vi CMake_build.sh
#!/bin/bash
set -x
BASEPATH=.
NDKPATH=/AndroidSDK/ndk-bundle
CMAKEPATH=/AndroidSDK/cmake/3.6.4111459/bin
PLATFORM=arm64-v8a
BUILDTYPE=Debug
#rm -rf CMakeCache.txt
#rm -rf CMakeFiles
#rm -rf cmake_install.cmake
#rm -rf Makefile
#rm -rf CTestTestfile.cmake
${CMAKEPATH}/cmake \
-DCMAKE_TOOLCHAIN_FILE=${NDKPATH}/build/cmake/android.toolchain.cmake \
-DANDROID_ABI=${PLATFORM} \
-DANDROID_NDK=${NDKPATH} \
-DANDROID_NATIVE_API_LEVEL=29 \
-DANDROID_PLATFORM=android-29 \
-DANDROID_STL=c++_shared \
-DCMAKE_BUILD_TYPE=${BUILDTYPE} \
-DANDROID_TOOLCHAIN=clang \
-DBOOST_ROOT=${BASEPATH}/boost/arm64-v8a \
-DCMAKE_INSTALL_PREFIX=${BASEPATH}/out/ \
-DENABLE_COMPAT=1 \
-DVSOMEIP_INSTALL_ROUTINGMANAGERD=ON \
-DENABLE_MULTIPLE_ROUTING_MANAGERS=1 \
${BASEPATH}
make VERBOSE=1
make install
set +x
$ vi CMakeLists.txt
…
# OS
if (${CMAKE_SYSTEM_NAME} MATCHES “Android”)
set(OS “Android”)
set(DL_LIBRARY “”)
set(EXPORTSYMBOLS “”)
set(NO_DEPRECATED “”)
set(OPTIMIZE “”)
set(OS_CXX_FLAGS “-Wno-error=format-security -D_GLIBCXX_USE_NANOSLEEP -pthread -O -Wall -Wextra -Wformat -Wformat-security -Wconversion -fexceptions -fstrict-aliasing -fstack-protector-strong -fasynchronous-unwind-tables -fno-omit-frame-pointer -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -fPIE -pie -Wl,-z,relro,-z,now”)
endif (${CMAKE_SYSTEM_NAME} MATCHES “Android”)
if (${CMAKE_SYSTEM_NAME} MATCHES “Linux”)
…
# Boost
set(BOOST_ROOT ${CMAKE_SOURCE_DIR}/../Boost-for-Android/build/out/${ANDROID_ABI})
set(BOOST_INCLUDEDIR ${BOOST_ROOT}/include/boost-1_70)
set(BOOST_LIBRARYDIR ${BOOST_ROOT}/lib)
set(Boost_FOUND 1)
set(Boost_INCLUDE_DIR ${BOOST_ROOT}/include/boost-1_70)
set(Boost_LIBRARY_DIR ${BOOST_ROOT}/lib)
set(Boost_VERSION 107000)
#find_package( Boost 1.55 COMPONENTS system thread log REQUIRED )
include_directories( ${Boost_INCLUDE_DIR} )
…
else()
# set (CMAKE_CXX_FLAGS “${CMAKE_CXX_FLAGS} -D${OS} ${OS_CXX_FLAGS} -DBOOST_LOG_DYN_LINK -g ${OPTIMIZE} -std=c++11 ${NO_DEPRECATED} ${EXPORTSYMBOLS}”)
set (CMAKE_CXX_FLAGS “${CMAKE_CXX_FLAGS} -D${OS} ${OS_CXX_FLAGS} -g ${OPTIMIZE} -std=c++11 ${NO_DEPRECATED} ${EXPORTSYMBOLS}”)
add_library(boost_system STATIC IMPORTED)
set_target_properties(boost_system PROPERTIES IMPORTED_LOCATION ${Boost_LIBRARY_DIR}/libboost_system-clang-mt-a64-1_70.a)
add_library(boost_thread STATIC IMPORTED)
set_target_properties(boost_thread PROPERTIES IMPORTED_LOCATION ${Boost_LIBRARY_DIR}/libboost_thread-clang-mt-a64-1_70.a)
add_library(boost_log_setup STATIC IMPORTED)
set_target_properties(boost_log_setup PROPERTIES IMPORTED_LOCATION ${Boost_LIBRARY_DIR}/libboost_log_setup-clang-mt-a64-1_70.a)
add_library(boost_log STATIC IMPORTED)
set_target_properties(boost_log PROPERTIES IMPORTED_LOCATION ${Boost_LIBRARY_DIR}/libboost_log-clang-mt-a64-1_70.a)
add_library(boost_filesystem STATIC IMPORTED)
set_target_properties(boost_filesystem PROPERTIES IMPORTED_LOCATION ${Boost_LIBRARY_DIR}/libboost_filesystem-clang-mt-a64-1_70.a)
set(Boost_LIBRARIES “log” “boost_system” “boost_thread” “boost_log” “boost_log_setup” “boost_filesystem”)
# set(USE_RT “rt”)
endif()
################################################################################
# Configuration library
################################################################################
…
$ vi implementation/helper/1.70/boost/asio/detail/reactive_socket_recvfrom_op_ext_local.hpp
reactive_socket_recvfrom_op_base_ext_local(socket_type socket, int protocol_type,
const MutableBufferSequence& buffers, Endpoint& endpoint,
socket_base::message_flags flags, func_type complete_func)
修改这行:
: reactor_op(&reactive_socket_recvfrom_op_base_ext_local::do_perform, complete_func),
为:
: reactor_op_ext_local(&reactive_socket_recvfrom_op_base_ext_local::do_perform, complete_func),
把Android AOSP的log.h拷贝过来(注意log名字大小写变化):
$ mkdir interface/utils
$ cp ../androidP/system/core/include/android/log.h ./interface/utils/Log.h
$ vi ./interface/utils/Log.h
底部添加:
#define LOG_TAG “VSOMEIP”
#define ALOGV(…) __android_log_print(ANDROID_LOG_VERBOSE,LOG_TAG,__VA_ARGS__)
#define ALOGD(…) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
#define ALOGI(…) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
#define ALOGW(…) __android_log_print(ANDROID_LOG_WARN,LOG_TAG,__VA_ARGS__)
#define ALOGE(…) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)
$ vi implementation/configuration/include/internal_android.hpp
#define VSOMEIP_CFG_LIBRARY “libvsomeip3-cfg.so”
#define VSOMEIP_SD_LIBRARY “libvsomeip3-sd.so”
#define VSOMEIP_E2E_LIBRARY “libvsomeip3-e2e.so”
编译:
$ ./CMake_build.sh
生成位置(其中路由管理是个可执行文件,在bin子目录):
$ ll out/*
out/bin:
routingmanagerd
out/etc: (注意这个etc里面的*.json文件为客户端和服务端配置文件模板,后面可以以这个为基础进行修改)
vsomeip
out/include:
compat vsomeip
out/lib:
cmake libvsomeip3-e2e.so libvsomeip3-sd.so libvsomeip3.so libvsomeip.so pkgconfig
使用Android NDK编译CommonAPI的核心库:
$ tar -zxvf capicxx-core-runtime-3.1.12.6.tar.gz
$ cd capicxx-core-runtime-3.1.12.6/
$ vi CMake_build.sh
#!/bin/bash
set -x
BASEPATH=.
NDKPATH=/AndroidSDK/ndk-bundle
CMAKEPATH=/AndroidSDK/cmake/3.6.4111459/bin
PLATFORM=arm64-v8a
BUILDTYPE=Debug
#rm -rf CMakeCache.txt
#rm -rf CMakeFiles
#rm -rf cmake_install.cmake
#rm -rf Makefile
#rm -rf CTestTestfile.cmake
${CMAKEPATH}/cmake \
-DCMAKE_TOOLCHAIN_FILE=${NDKPATH}/build/cmake/android.toolchain.cmake \
-DANDROID_ABI=${PLATFORM} \
-DANDROID_NDK=${NDKPATH} \
-DANDROID_NATIVE_API_LEVEL=29 \
-DANDROID_PLATFORM=android-29 \
-DANDROID_STL=c++_shared \
-DCMAKE_BUILD_TYPE=${BUILDTYPE} \
-DANDROID_TOOLCHAIN=clang \
-DCMAKE_INSTALL_PREFIX=${BASEPATH}/out/ \
${BASEPATH}
make VERBOSE=1
make install
set +x
$ vi CMakeLists.txt
…
ELSE ()
set(CMAKE_CXX_FLAGS “${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations -Wno-attributes -std=c++11 -Wall -Wextra -Wformat -Wformat-security -Wconversion -fexceptions -fstrict-aliasing -fstack-protector -fasynchronous-unwind-tables -fno-omit-frame-pointer -Werror -DCOMMONAPI_INTERNAL_COMPILATION”)
ENDIF(MSVC)
…
编译:
$ ./CMake_build.sh
生成位置(其中路由管理是个可执行文件,在bin子目录):
$ ll out/*
out/include:
CommonAPI-3.1
out/lib:
cmake libCommonAPI.so
使用Android NDK编译CommonAPI的核心库关于someip的适配库(只支持vsomeip的COMPAT方式):
$ tar -zxvf capicxx-someip-runtime-3.1.12.17.tar.gz
$ cd capicxx-someip-runtime-3.1.12.17/
$ vi CMake_build.sh
#!/bin/bash
set -x
BASEPATH=.
NDKPATH=/AndroidSDK/ndk-bundle
CMAKEPATH=/AndroidSDK/cmake/3.6.4111459/bin
PLATFORM=arm64-v8a
BUILDTYPE=Debug
#rm -rf CMakeCache.txt
#rm -rf CMakeFiles
#rm -rf cmake_install.cmake
#rm -rf Makefile
#rm -rf CTestTestfile.cmake
${CMAKEPATH}/cmake \
-DCMAKE_TOOLCHAIN_FILE=${NDKPATH}/build/cmake/android.toolchain.cmake \
-DANDROID_ABI=${PLATFORM} \
-DANDROID_NDK=${NDKPATH} \
-DANDROID_NATIVE_API_LEVEL=29 \
-DANDROID_PLATFORM=android-29 \
-DANDROID_STL=c++_shared \
-DCMAKE_BUILD_TYPE=${BUILDTYPE} \
-DANDROID_TOOLCHAIN=clang \
-DCMAKE_INSTALL_PREFIX=${BASEPATH}/out/ \
${BASEPATH}
make VERBOSE=1
make install
set +x
$ vi CMakeLists.txt
…
set(CommonAPI_DIR “${CMAKE_SOURCE_DIR}/../capicxx-core-runtime-3.1.12.6”)
set(vsomeip_DIR “${CMAKE_SOURCE_DIR}/../vsomeip-3.1.7.1”)
if (“${USE_INSTALLED_COMMONAPI}” STREQUAL “ON”)
FIND_PACKAGE(CommonAPI 3.1.12 REQUIRED CONFIG NO_CMAKE_PACKAGE_REGISTRY)
else()
FIND_PACKAGE(CommonAPI 3.1.12 REQUIRED CONFIG NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH)
endif()
message(STATUS “CommonAPI_CONSIDERED_CONFIGS: ${CommonAPI_CONSIDERED_CONFIGS}”)
message(STATUS “COMMONAPI_INCLUDE_DIRS: ${COMMONAPI_INCLUDE_DIRS}”)
message(STATUS “CommonAPI Version: ${CommonAPI_VERSION}”)
# Boost
set(BOOST_ROOT ${CMAKE_SOURCE_DIR}/../Boost-for-Android/build/out/${ANDROID_ABI})
set(BOOST_INCLUDEDIR ${BOOST_ROOT}/include/boost-1_70)
set(BOOST_LIBRARYDIR ${BOOST_ROOT}/lib)
set(Boost_FOUND 1)
set(Boost_INCLUDE_DIR ${BOOST_ROOT}/include/boost-1_70)
set(Boost_LIBRARY_DIR ${BOOST_ROOT}/lib)
set(Boost_VERSION 107000)
#find_package( Boost 1.54 COMPONENTS system thread log REQUIRED )
include_directories( ${Boost_INCLUDE_DIR} )
add_library(boost_system STATIC IMPORTED)
set_target_properties(boost_system PROPERTIES IMPORTED_LOCATION ${Boost_LIBRARY_DIR}/libboost_system-clang-mt-a64-1_70.a)
add_library(boost_thread STATIC IMPORTED)
set_target_properties(boost_thread PROPERTIES IMPORTED_LOCATION ${Boost_LIBRARY_DIR}/libboost_thread-clang-mt-a64-1_70.a)
add_library(boost_log_setup STATIC IMPORTED)
set_target_properties(boost_log_setup PROPERTIES IMPORTED_LOCATION ${Boost_LIBRARY_DIR}/libboost_log_setup-clang-mt-a64-1_70.a)
add_library(boost_log STATIC IMPORTED)
set_target_properties(boost_log PROPERTIES IMPORTED_LOCATION ${Boost_LIBRARY_DIR}/libboost_log-clang-mt-a64-1_70.a)
set(Boost_LIBRARIES “log” “boost_system” “boost_thread” “boost_log” “boost_log_setup”)
find_package (vsomeip 2.99.99 REQUIRED)
message(STATUS “vsomeip version: ${vsomeip_VERSION}”)
set(VSOMEIP_INCLUDE_DIRS ${vsomeip_DIR}/out/include/compat)
…
注释掉_WIN32:
$ vi include/CommonAPI/SomeIP/StringEncoder.hpp
//#if _WIN32
#define LITTLE_ENDIAN 1234
#define BIG_ENDIAN 4321
//#endif
编译:
$ ./CMake_build.sh
生成位置(其中路由管理是个可执行文件,在bin子目录):
$ ls out/*
out/include:
CommonAPI-3.1
out/lib:
cmake libCommonAPI-SomeIP.so pkgconfig
从fidl(Franca IDL)、fdepl生成c++代码的工具(需要java来运行,可以通过研究这两个项目来理解fidl语法和fdepl语法):
CommonAPI-SOMEIP:
$ unzip commonapi_someip_generator.zip -d commonapi_someip_generator
$ commonapi_someip_generator/commonapi-someip-generator-linux-x86_64 -h
其中fepl部署文件的语法参考:
CommonAPI:
$ wget https://github.com/GENIVI/capicxx-core-tools/releases/download/3.1.12.4/commonapi-generator.zip
$ unzip commonapi-generator.zip -d commonapi-generator
$ commonapi-generator/commonapi-generator-linux-x86_64 -h
其中fidl接口定义文件的语法参考:
测试:
建立一个测试项目:
$ mkdir vsomeip_project
$ cd vsomeip_project/
$ mkdir fidl
建立fidl文件和fdepl文件:
$ vi fidl/HelloWorld.fidl
package commonapi
interface HelloWorld {
version {major 1 minor 0}
method sayHello {
in {
String name
}
out {
String message
}
}
}
$ vi fidl/HelloWorld.fdepl
import “platform:/plugin/org.genivi.commonapi.someip/deployment/CommonAPI-SOMEIP_deployment_spec.fdepl“
import “HelloWorld.fidl”
define org.genivi.commonapi.someip.deployment for interface commonapi.HelloWorld {
SomeIpServiceID = 4660
method sayHello {
SomeIpMethodID = 33000
}
}
define org.genivi.commonapi.someip.deployment for provider MyService {
instance commonapi.HelloWorld {
InstanceId = “test”
SomeIpInstanceID = 22136
}
}
由fdepl和fidl生成代码:
$ ../commonapi-generator/commonapi-generator-linux-x86_64 -ll verbose –skel fidl/HelloWorld.fidl
$ ../commonapi-generator/commonapi-generator-linux-x86_64 -ll verbose fidl/HelloWorld.fdepl
$ ../commonapi_someip_generator/commonapi-someip-generator-linux-x86_64 -ll verbose fidl/HelloWorld.fdepl
生成位置:
$ ls src-gen/v1/commonapi/
HelloWorld.hpp HelloWorldProxy.hpp HelloWorldSomeIPProxy.cpp HelloWorldSomeIPStubAdapter.hpp HelloWorldStub.hpp
HelloWorldInstanceIds.hpp HelloWorldSomeIPDeployment.cpp HelloWorldSomeIPProxy.hpp HelloWorldStubDefault.cpp
HelloWorldProxyBase.hpp HelloWorldSomeIPDeployment.hpp HelloWorldSomeIPStubAdapter.cpp HelloWorldStubDefault.hpp
建立客户端代码:
$ mkdir src
$ mkdir build
$ vi src/HelloWorldClient.cpp
#include <iostream>
#include <string>
#include <unistd.h>
#include <CommonAPI/CommonAPI.hpp>
#include <v1/commonapi/HelloWorldProxy.hpp>
using namespace v1::commonapi;
int main() {
std::shared_ptr < CommonAPI::Runtime > runtime = CommonAPI::Runtime::get();
std::shared_ptr<HelloWorldProxy<>> myProxy = runtime->buildProxy<HelloWorldProxy>(“local”, “test”);
std::cout << “Checking availability!” << std::endl;
while (!myProxy->isAvailable())
usleep(10);
std::cout << “Available…” << std::endl;
CommonAPI::CallStatus callStatus;
std::string returnMessage;
myProxy->sayHello(“Bob”, callStatus, returnMessage);
std::cout << “Got message: ‘” << returnMessage << “‘\n”;
return 0;
}
建立服务端代码:
$ vi src/HelloWorldService.cpp
#include <iostream>
#include <thread>
#include <CommonAPI/CommonAPI.hpp>
#include “HelloWorldStubImpl.hpp”
using namespace std;
int main() {
std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::get();
std::shared_ptr<HelloWorldStubImpl> myService = std::make_shared<HelloWorldStubImpl>();
runtime->registerService(“local”, “test”, myService);
std::cout << “Successfully Registered Service!” << std::endl;
while (true) {
std::cout << “Waiting for calls… (Abort with CTRL+C)” << std::endl;
std::this_thread::sleep_for(std::chrono::seconds(30));
}
return 0;
}
建立服务实现代码和头文件:
$ vi src/HelloWorldStubImpl.hpp
#ifndef HELLOWORLDSTUBIMPL_H_
#define HELLOWORLDSTUBIMPL_H_
#include <CommonAPI/CommonAPI.hpp>
#include <v1/commonapi/HelloWorldStubDefault.hpp>
class HelloWorldStubImpl: public v1::commonapi::HelloWorldStubDefault {
public:
HelloWorldStubImpl();
virtual ~HelloWorldStubImpl();
virtual void sayHello(const std::shared_ptr<CommonAPI::ClientId> _client, std::string _name, sayHelloReply_t _return);
};
#endif /* HELLOWORLDSTUBIMPL_H_ */
$ vi src/HelloWorldStubImpl.cpp
#include “HelloWorldStubImpl.hpp”
HelloWorldStubImpl::HelloWorldStubImpl() { }
HelloWorldStubImpl::~HelloWorldStubImpl() { }
void HelloWorldStubImpl::sayHello(const std::shared_ptr<CommonAPI::ClientId> _client, std::string _name, sayHelloReply_t _reply) {
std::stringstream messageStream;
messageStream << “Hello ” << _name << “!”;
std::cout << “sayHello(‘” << _name << “‘): ‘” << messageStream.str() << “‘\n”;
_reply(messageStream.str());
};
建立cmake编译文件:
$ vi CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
set(CMAKE_CXX_FLAGS “${CMAKE_CXX_FLAGS} -pthread -std=c++11”)
include_directories(
.
src-gen
${CMAKE_SOURCE_DIR}/../capicxx-core-runtime-3.1.12.6/out/include/CommonAPI-3.1
${CMAKE_SOURCE_DIR}/../capicxx-someip-runtime-3.1.12.17/out/include/CommonAPI-3.1
${CMAKE_SOURCE_DIR}/../vsomeip-3.1.7.1/out/include/compat
)
link_directories(
${CMAKE_SOURCE_DIR}/../capicxx-core-runtime-3.1.12.6/out/lib
${CMAKE_SOURCE_DIR}/../capicxx-someip-runtime-3.1.12.17/out/lib
${CMAKE_SOURCE_DIR}/../vsomeip-3.1.7.1/out/lib
)
add_executable(HelloWorldClient
src/HelloWorldClient.cpp
src-gen/v1/commonapi/HelloWorldSomeIPProxy.cpp
src-gen/v1/commonapi/HelloWorldSomeIPDeployment.cpp
)
if (${CMAKE_SYSTEM_NAME} MATCHES “Android”)
target_link_libraries(HelloWorldClient CommonAPI CommonAPI-SomeIP vsomeip vsomeip3 c++_shared log)
else()
target_link_libraries(HelloWorldClient CommonAPI CommonAPI-SomeIP vsomeip vsomeip3 pthread)
endif()
add_executable(HelloWorldService
src/HelloWorldService.cpp
src/HelloWorldStubImpl.cpp
src-gen/v1/commonapi/HelloWorldSomeIPStubAdapter.cpp
src-gen/v1/commonapi/HelloWorldStubDefault.cpp
src-gen/v1/commonapi/HelloWorldSomeIPDeployment.cpp
)
if (${CMAKE_SYSTEM_NAME} MATCHES “Android”)
target_link_libraries(HelloWorldService CommonAPI CommonAPI-SomeIP vsomeip vsomeip3 c++_shared log)
else()
target_link_libraries(HelloWorldService CommonAPI CommonAPI-SomeIP vsomeip vsomeip3 pthread)
endif()
set(INSTALL_BIN_DIR bin CACHE PATH “Installation directory for binaries”)
install(FILES
“${CMAKE_SOURCE_DIR}/../capicxx-core-runtime-3.1.12.6/out/lib/libCommonAPI.so”
“${CMAKE_SOURCE_DIR}/../capicxx-someip-runtime-3.1.12.17/out/lib/libCommonAPI-SomeIP.so”
“${CMAKE_SOURCE_DIR}/../vsomeip-3.1.7.1/out/lib/libvsomeip.so”
“${CMAKE_SOURCE_DIR}/../vsomeip-3.1.7.1/out/lib/libvsomeip3.so”
“${CMAKE_SOURCE_DIR}/../vsomeip-3.1.7.1/out/lib/libvsomeip3-sd.so”
“${CMAKE_SOURCE_DIR}/../vsomeip-3.1.7.1/out/lib/libvsomeip3-e2e.so”
“${NDK_PATH}/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/libc++_shared.so”
DESTINATION “lib”
)
install(TARGETS HelloWorldClient
RUNTIME DESTINATION ${INSTALL_BIN_DIR}
LIBRARY DESTINATION ${INSTALL_LIB_DIR}
ARCHIVE DESTINATION ${INSTALL_LIB_DIR}
)
install(FILES
“config/client.json”
DESTINATION “config”
)
install(TARGETS HelloWorldService
RUNTIME DESTINATION ${INSTALL_BIN_DIR}
LIBRARY DESTINATION ${INSTALL_LIB_DIR}
ARCHIVE DESTINATION ${INSTALL_LIB_DIR}
)
install(FILES
“config/service.json”
DESTINATION “config”
)
$ vi CMake_build.sh
#!/bin/bash
set -x
BASEPATH=.
NDKPATH=/AndroidSDK/ndk-bundle
CMAKEPATH=/AndroidSDK/cmake/3.6.4111459/bin
PLATFORM=arm64-v8a
BUILDTYPE=Debug
#rm -rf CMakeCache.txt
#rm -rf CMakeFiles
#rm -rf cmake_install.cmake
#rm -rf Makefile
#rm -rf CTestTestfile.cmake
${CMAKEPATH}/cmake \
-DCMAKE_TOOLCHAIN_FILE=${NDKPATH}/build/cmake/android.toolchain.cmake \
-DANDROID_ABI=${PLATFORM} \
-DANDROID_NDK=${NDKPATH} \
-DANDROID_NATIVE_API_LEVEL=29 \
-DANDROID_PLATFORM=android-29 \
-DANDROID_STL=c++_shared \
-DNDK_PATH=${NDKPATH} \
-DCMAKE_BUILD_TYPE=${BUILDTYPE} \
-DANDROID_TOOLCHAIN=clang \
-DCMAKE_INSTALL_PREFIX=${BASEPATH}/out/ \
${BASEPATH}
make VERBOSE=1
make install
set +x
编译:
$ ./CMake_build.sh
生成位置:
$ ls out/bin/
HelloWorldClient HelloWorldService
建立配置文件(IP为本客户端ip,而非服务端ip;如果客户端和服务器在同一台机器上,而routing又相同,则消息不会走到网络接口而会直接在routing处环回了):
$ mkdir config
$ vi config/client.json
{
“unicast” : “127.0.0.1”,
“netmask” : “255.255.255.0”,
“logging” :
{
“level” : “debug”,
“console” : “true”,
“file” : {
“enable” : “true”,
“path” : “/storage/vsomeip_client.log”
},
“dlt” : “true”
},
“diagnosis”:”0x11″,
“diagnosis_mask”:”0xFF00″,
“applications” :
[
{
“name” : “vsomeip_Client”,
“id” : “0x1343”
}
],
“routing” : “vsomeip-route”,
“service-discovery” :
{
“enable” : “true”,
“multicast” : “239.192.255.251”,
“port” : “30490”,
“protocol” : “udp”
}
}
(IP为本服务端ip,而非客户端ip)
$ vi config/service.json
{
“unicast”:”127.0.0.1″,
“netmask”:”255.255.255.0″,
“logging”:{
“level”: “trace”,
“console”: “true”,
“file”:{
“enable”:”true”,
“path”:”/storage/vsomeip_service.log”
},
“dlt”: “false”
},
“diagnosis”:”0x18″,
“diagnosis_mask”:”0xFF00″,
“applications”:[
{
“name”:”vsomeip_Service”,
“id”:”0x1277″
}
],
“servicegroups” :[
{
“name”:”default”,
“unicast”:”127.0.0.1″,
“netmask”:”255.255.255.0″,
“services”:[
{
“service”:”0x1234″,
“instance”:”0x5678″,
“multicast”:{
“address”:”239.192.255.251″,
“port”:”56001″
},
“reliable”:{
“port”:”56001″,
“enable-magic-cookies”:”false”
},
“unreliable”:”31000″,
“events”:[
{
“event”:”0x8001″,
“is_field”:”false”,
“is_reliable”:”false”
},
],
“eventgroups”:[
{
“eventgroup”:”0x0001″,
“events”:[
“0x8001”,
]
}
]
}
],
}
],
“routing”:”vsomeip-route”,
“service-discovery”:{
“enable”:”true”,
“multicast”:”239.192.255.251″,
“port”:”30490″,
“protocol”:”udp”,
“initial_delay_min”:”10″,
“initial_delay_max”:”100″,
“repetitions_base_delay”:”30″,
“repetitions_max”:”3″,
“ttl”:”3″,
“cyclic_offer_delay”:”1000″,
“request_response_delay”:”500″
}
}
运行服务端:
dos> adb root
dos> adb remount
dos> adb shell
# mkdir vsomeip
dos> adb push …\out /vsomeip/
dos> adb shell
# cd /vsomeip/
# chmod +x bin/*
# export LD_LIBRARY_PATH=./lib:${LD_LIBRARY_PATH}
# export VSOMEIP_CONFIGURATION_FILE=./config/service.json
# export VSOMEIP_APPLICATION_NAME=vsomeip_Service
# ./bin/HelloWorldService
运行客户端:
dos> adb shell
# cd /vsomeip/
# chmod +x bin/*
# export LD_LIBRARY_PATH=./lib:${LD_LIBRARY_PATH}
# export VSOMEIP_CONFIGURATION_FILE=./config/client.json
# export VSOMEIP_APPLICATION_NAME=vsomeip_Client
# ./bin/HelloWorldClient
可以看到连接到了服务端,并且显示服务端返回的“Hello Bob”