Skip to content

Commit 0632c22

Browse files
authored
Android emulator.Add script and manual CI jobs (#853)
Script do: - build SDK with needed options for Android (API=25,ABI=arm64-v8a) - create AndroidVirtualDevice(AVD) - start AVD via embeded SDK emulator - run trivial adb command to check that device is ON. (.apk installation to be added later) Everything can run on: - Gitlab CI by using our Android image - Azure Pipelines CI by using MacOS image. Resolves: OLPEDGE-1774 Signed-off-by: Yaroslav Stefinko <ext-yaroslav.stefinko@here.com>
1 parent eed1d0d commit 0632c22

File tree

3 files changed

+114
-1
lines changed

3 files changed

+114
-1
lines changed

.gitlab-ci.yml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ image: ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${DOCKER_IMAGE_VERSION}
33
variables:
44
LD_PRELOAD: "/lib/x86_64-linux-gnu/libSegFault.so"
55
SEGFAULT_SIGNALS: "all"
6+
ADB_INSTALL_TIMEOUT: "8"
67

78
stages:
89
- build
@@ -176,4 +177,24 @@ pages:
176177
- schedules
177178
variables:
178179
- $FV
179-
- $NV
180+
- $NV
181+
182+
test_android_emulator:
183+
stage: test
184+
tags:
185+
- docker-prod
186+
image: ${DOCKER_REGISTRY}/${DOCKER_IMAGE_ANDROID}:${DOCKER_IMAGE_ANDROID_VERSION}
187+
script:
188+
- $CI_PROJECT_DIR/scripts/android/build-test-emulator.sh
189+
when: manual
190+
only:
191+
- master
192+
- branches
193+
artifacts:
194+
reports:
195+
junit:
196+
- reports/*.xml
197+
when: always
198+
paths:
199+
- reports
200+
expire_in: 1 year

azure-pipelines.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,18 @@ jobs:
5454
- bash: ANDROID_NDK_HOME=$(ANDROID_NDK_HOME) && scripts/android/build.sh
5555
displayName: 'Android build and Examples'
5656

57+
- job: Android_Emulator
58+
pool:
59+
vmImage: 'macOS-10.14'
60+
condition: eq(variables['Build.Reason'], 'Manual')
61+
variables:
62+
ANDROID_NDK_HOME: $(ANDROID_HOME)/ndk-bundle
63+
steps:
64+
- bash: ls -la $(ANDROID_NDK_HOME)/build/cmake/android.toolchain.cmake
65+
displayName: 'Verification of cmake script'
66+
- bash: ANDROID_NDK_HOME=$(ANDROID_NDK_HOME) && scripts/android/build-test-emulator.sh
67+
displayName: 'Android Test'
68+
5769
- job: Linux_build_clang
5870
pool:
5971
vmImage: 'ubuntu-18.04'
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/bin/bash -ex
2+
#
3+
# Copyright (C) 2020 HERE Europe B.V.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
# SPDX-License-Identifier: Apache-2.0
18+
# License-Filename: LICENSE
19+
20+
# Android Only Variables
21+
export ANDROID_ABI="arm64-v8a"
22+
export ANDROID_API=25
23+
24+
mkdir -p build && cd build
25+
26+
echo ""
27+
echo ""
28+
echo "*************** $VARIANT Build SDK for C++ ********** Start ***************"
29+
CMAKE_COMMAND="cmake .. -G Ninja -DCMAKE_TOOLCHAIN_FILE=$NDK_ROOT/build/cmake/android.toolchain.cmake \
30+
-DANDROID_PLATFORM=android-$ANDROID_API -DANDROID_STL=c++_static -DANDROID_ABI=$ANDROID_ABI"
31+
NINJA_COMMAND="ninja -j$(nproc)"
32+
33+
echo ""
34+
echo " ---- Calling $CMAKE_COMMAND"
35+
${CMAKE_COMMAND}
36+
37+
# Run CMake. Warnings and errors are saved to build/CMakeFiles/CMakeOutput.log and
38+
# build/CMakeFiles/CMakeError.log.
39+
# -- We link Edge SDK as shared libraries in order to use shadowing for unit tests.
40+
# -- We build the examples.
41+
echo ""
42+
echo " ---- Calling ${NINJA_COMMAND}"
43+
${NINJA_COMMAND}
44+
cd -
45+
46+
ls -la $ANDROID_HOME
47+
export PATH=$PATH:$ANDROID_HOME/tools/bin/
48+
sdkmanager --list
49+
50+
# Install AVD files
51+
echo "y" | sdkmanager --install "system-images;android-$ANDROID_API;google_apis;$ANDROID_ABI"
52+
53+
# Create emulator
54+
echo "no" | avdmanager create avd -n android_emulator -k "system-images;android-$ANDROID_API;google_apis;$ANDROID_ABI" --force
55+
echo "AVD created"
56+
$ANDROID_HOME/emulator/emulator -list-avds
57+
58+
echo "Starting emulator in background"
59+
# Start emulator
60+
nohup $ANDROID_HOME/emulator/emulator -avd android_emulator -no-snapshot -noaudio \
61+
-no-boot-anim -gpu off -no-accel -no-window -camera-back none -camera-front none -selinux permissive \
62+
-qemu -m 2048 > /dev/null 2>&1 &
63+
64+
65+
$ANDROID_HOME/platform-tools/adb wait-for-device
66+
67+
A=$($ANDROID_HOME/platform-tools/adb shell getprop sys.boot_completed | tr -d '\r')
68+
while [ "$A" != "1" ]; do
69+
sleep 2
70+
A=$($ANDROID_HOME/platform-tools/adb shell getprop sys.boot_completed | tr -d '\r')
71+
done
72+
73+
# Running some trivial command like pressing Menu button.
74+
$ANDROID_HOME/platform-tools/adb shell input keyevent 82
75+
76+
#Showing list of devices connected to host
77+
$ANDROID_HOME/platform-tools/adb devices
78+
79+
### In this place, we plan to run .apk as test application inside emulator.
80+
echo "Emulator started"

0 commit comments

Comments
 (0)