简体   繁体   English

无法使用Gitlab-CI在Docker容器中运行Android应用程序

[英]Unable to run an Android application in a Docker container with Gitlab-CI

I've been struggling with a problem for a couple of days now and I hope somebody will be able to help me... 我一直在努力解决问题几天,我希望有人能够帮助我......

I try to use gitlab ci for my basic android application project. 我尝试使用gitlab ci作为我的基本android应用程序项目。

Based on the following tutorial Setting up GitLab CI for Android projects , I wrote a .gitlab-ci.yml script : 基于以下教程为Android项目设置GitLab CI ,我编写了一个.gitlab-ci.yml脚本:

image: openjdk:8-jdk

variables:
  ANDROID_COMPILE_SDK: "25"
  ANDROID_BUILD_TOOLS: "25.0.1"
  ANDROID_SDK_TOOLS: "25.2.3"

before_script:
  - apt-get --quiet update --yes
  - apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1 libqt5widgets5
  - wget --quiet --output-document=tools.zip https://dl.google.com/android/repository/tools_r${ANDROID_SDK_TOOLS}-linux.zip
  - unzip tools.zip -d /sdk
  - rm tools.zip
  - echo y | /sdk/tools/android --silent update sdk --no-ui --all --filter android-${ANDROID_COMPILE_SDK}
  - echo y | /sdk/tools/android --silent update sdk --no-ui --all --filter platform-tools
  - echo y | /sdk/tools/android --silent update sdk --no-ui --all --filter build-tools-${ANDROID_BUILD_TOOLS}
  - echo y | /sdk/tools/android --silent update sdk --no-ui --all --filter extra-android-m2repository
  - echo y | /sdk/tools/android --silent update sdk --no-ui --all --filter extra-google-google_play_services
  - echo y | /sdk/tools/android --silent update sdk --no-ui --all --filter extra-google-m2repository
  - export ANDROID_HOME=/sdk
  - export PATH=$PATH:$ANDROID_HOME/platform-tools/
  - chmod +x ./gradlew

stages:
  - test

functionalTests:
  stage: test
  script:
    - echo y | /sdk/tools/android --silent update sdk --no-ui --all --filter sys-img-x86-google_apis-${ANDROID_COMPILE_SDK}
    - echo no | /sdk/tools/android create avd -n test -t android-${ANDROID_COMPILE_SDK} --abi google_apis/x86
    - /sdk/tools/emulator64-x86 -avd test -no-accel -no-window -no-audio &
    - adb wait-for-device
    - ./gradlew assembleDebug
    - ./gradlew assembleDebugAndroidTest
    - adb devices
    - adb shell service list
    - adb shell input keyevent 82 # Unlock device to allow install...
    - adb install -r app/build/outputs/apk/app-debug.apk
    - adb install -r app/build/outputs/apk/app-debug-androidTest.apk
    - adb shell am instrument -w -r -e debug false -e class com.example.myfirstapp.ManageItemListTest com.example.myfirstapp.test/android.support.test.runner.AndroidJUnitRunner
  artifacts:
    paths:
    - app/build/outputs/

My first difficulty - as somebody mentioned in the tutorial's comments - is that I have no way to manage and enable hardware acceleration in a docker container. 我的第一个难点 - 正如教程评论中提到的那样 - 是我无法在docker容器中管理和启用硬件加速。

For now, I added the '-no-accel' option when lauching the AVD to get the script further executed. 现在,我在推出AVD时添加了'-no-accel'选项以进一步执行脚本。

But the main problem is that 'adb shell input keyevent 82' as well as the following installation commands fail. 但主要问题是“adb shell输入keyevent 82”以及以下安装命令失败。

The emulated device is running but is apparently missing lots of services as shown below : 模拟设备正在运行,但显然缺少许多服务,如下所示:

Found 17 services:
0   media.camera: [android.hardware.ICameraService]
1   media.resource_manager: [android.media.IResourceManagerService]
2   media.player: [android.media.IMediaPlayerService]
3   media.sound_trigger_hw: [android.hardware.ISoundTriggerHwService]
4   media.radio: [android.hardware.IRadioService]
5   media.audio_policy: [android.media.IAudioPolicyService]
6   media.drm: [android.media.IMediaDrmService]
7   media.extractor: [android.media.IMediaExtractorService]
8   media.audio_flinger: [android.media.IAudioFlinger]
9   drm.drmManager: [drm.IDrmManagerService]
10  media.codec: [android.media.IMediaCodecService]
11  gpu: [android.ui.IGpuService]
12  SurfaceFlinger: [android.ui.ISurfaceComposer]
13  android.service.gatekeeper.IGateKeeperService: []
14  android.security.keystore: [android.security.IKeystoreService]
15  android.hardware.fingerprint.IFingerprintDaemon: []
16  batteryproperties: [android.os.IBatteryPropertiesRegistrar]

Only 17 services are started when 91 do actually run for an AVD locally launched on my desktop with Android Studio. 当91实际运行在我的桌面上使用Android Studio进行本地启动的AVD时,只启动了17项服务。

The package manager (package: [android.content.pm.IPackageManager]) is among the missing services... 包管理器(包:[android.content.pm.IPackageManager])是缺少的服务之一......

Can anybody tell me what happens and what to do ? 谁能告诉我发生了什么以及该怎么做?

Kind regards, 亲切的问候,

Laurent 洛朗

I finally found a solution using an ARM system image. 我终于找到了使用ARM系统映像的解决方案。 But one must also wait for all required services to start. 但是,还必须等待所有必需的服务启动。 Hereafter is the new script for anyone interested: 以下是任何感兴趣的人的新脚本:

image: openjdk:8-jdk

variables:
  ANDROID_COMPILE_SDK: "25"
  ANDROID_BUILD_TOOLS: "25.0.1"
  ANDROID_SDK_TOOLS: "25.2.3"

before_script:
  - apt-get --quiet update --yes
  - apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1 libqt5widgets5
  - wget --quiet --output-document=tools.zip https://dl.google.com/android/repository/tools_r${ANDROID_SDK_TOOLS}-linux.zip
  - unzip tools.zip -d /sdk
  - rm tools.zip
  - echo y | /sdk/tools/android --silent update sdk --no-ui --all --filter android-${ANDROID_COMPILE_SDK}
  - echo y | /sdk/tools/android --silent update sdk --no-ui --all --filter platform-tools
  - echo y | /sdk/tools/android --silent update sdk --no-ui --all --filter build-tools-${ANDROID_BUILD_TOOLS}
  - echo y | /sdk/tools/android --silent update sdk --no-ui --all --filter extra-android-m2repository
  - echo y | /sdk/tools/android --silent update sdk --no-ui --all --filter extra-google-google_play_services
  - echo y | /sdk/tools/android --silent update sdk --no-ui --all --filter extra-google-m2repository
  - export ANDROID_HOME=/sdk
  - export PATH=$PATH:$ANDROID_HOME/platform-tools/
  - chmod +x ./gradlew

stages:
  - test

functionalTests:
  stage: test
  script:
    - echo y | /sdk/tools/android --silent update sdk --no-ui --all --filter sys-img-armeabi-v7a-google_apis-${ANDROID_COMPILE_SDK}
    - echo no | /sdk/tools/android create avd -n test -t android-${ANDROID_COMPILE_SDK} --abi google_apis/armeabi-v7a
    - /sdk/tools/emulator64-arm -avd test -no-audio -gpu off -no-boot-anim -no-window &
    - adb wait-for-device
    - OUT=`adb shell service list | grep IPackageManager 2>&1 &` # Now wait for other services startup
    - until [[ $OUT  =~ .*IPackageManager.* ]]; do
    - sleep 20
    - OUT=`adb shell service list | grep IPackageManager 2>&1 &`
    - done
    - ./gradlew assembleDebug
    - ./gradlew assembleDebugAndroidTest
    - adb shell input keyevent 82 # Unlock device to allow install...
    - adb install -r app/build/outputs/apk/app-debug.apk
    - adb install -r app/build/outputs/apk/app-debug-androidTest.apk
    - adb shell am instrument -w -r -e debug false -e class com.example.myfirstapp.ManageItemListTest com.example.myfirstapp.test/android.support.test.runner.AndroidJUnitRunner
  artifacts:
    paths:
    - app/build/outputs/

For this basic example, the whole execution took more than 25 minutes to complete (with my test failing but that's another story... ;-)). 对于这个基本的例子,整个执行需要超过25分钟才能完成(我的测试失败但这是另一个故事... ;-))。 It would be great to have hardware acceleration... 有硬件加速会很棒......

Kind regards, 亲切的问候,

Laurent 洛朗

If you edit the gitlab runner .toml file and set "privileged:" to true, then you should be able to use hardware acceleration with the emulator. 如果您编辑gitlab runner .toml文件并将“privileged:”设置为true,那么您应该能够使用模拟器进行硬件加速。

This way you no longer have to use unsupported ARM images and instead can use intel images. 这样您就不再需要使用不受支持的ARM映像,而是可以使用intel映像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM