Travis CI错误:无法访问包管理器。系统正在运行吗?

时间:2017-10-12 19:20:39

标签: android gradle continuous-integration travis-ci

我正在尝试将travis CI用于我的一个项目,但我无法让它工作。我设法制作.travis.yml配置文件,并且构建正在传递。但令人惊讶的是,当我在几个小时后推送提交时,构建开始再次失败。此外,当我重新启动之前传递的构建时,构建失败。我不明白为什么会发生这种情况。

这是travis日志: Travis Log

和.travis.yml文件如下所示:

language: android
jdk: oraclejdk8
sudo: required
env:
  matrix:
    - ANDROID_TARGET=android-21  ANDROID_ABI=armeabi-v7a

android:
  components:
    - tools
    - platform-tools
    - tools
    - build-tools-26.0.2
    - $ANDROID_TARGET
    - android-26
    - sys-img-armeabi-v7a-$ANDROID_TARGET
  licenses:
    - android-sdk-preview-license-.+
    - android-sdk-license-.+
    - google-gdk-license-.+
before_install:
  - mkdir "$ANDROID_HOME/licenses" || true
  - echo -e "\n8933bad161af4178b1185d1a37fbf41ea5269c55" > "$ANDROID_HOME/licenses/android-sdk-license"
  - echo -e "\n84831b9409646a918e30573bab4c9c91346d8abd" > "$ANDROID_HOME/licenses/android-sdk-preview-license"
  - chmod +x gradlew
  - ./gradlew dependencies || true
before_cache:
  - rm -f  $HOME/.gradle/caches/modules-2/modules-2.lock
  - rm -fr $HOME/.gradle/caches/*/plugin-resolution/
cache:
  directories:
    - $HOME/.gradle/caches/
    - $HOME/.gradle/wrapper/
    - $HOME/.android/build-cache
before_script:
  # Create and start emulator
  - echo no | android create avd --force -n test -t $ANDROID_TARGET --abi $ANDROID_ABI
  - emulator -avd test -no-skin -no-audio -no-window &
  - adb wait-for-device
  - adb shell input keyevent 82 &

script: ./gradlew connectedAndroidTest

gradle文件相关代码段:

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.2"
    defaultConfig {
        applicationId "com.amit.realmmvp"
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    lintOptions {
        abortOnError false
    }
}

关于同一问题的堆栈溢出有类似的问题,但它们都与android studio和模拟器​​没有开始有关。但是,在travis配置文件中,我已经要求它等到模拟器使用- adb wait-for-device

上线

任何人都可以帮我解决这个问题吗?感谢。

修改

构建过程在这里失败:

:app:connectedDebugAndroidTestUnable to install /home/travis/build/AmitBarjatya/RealmMvp/app/build/outputs/apk/debug/app-debug.apk
com.android.ddmlib.InstallException: Unknown failure (Error: Could not access the Package Manager.  Is the system running?)
    at com.android.ddmlib.Device.installRemotePackage(Device.java:1004)
    at com.android.ddmlib.Device.installPackage(Device.java:911)
    at com.android.builder.testing.ConnectedDevice.installPackage(ConnectedDevice.java:122)
    at com.android.builder.internal.testing.SimpleTestCallable.call(SimpleTestCallable.java:126)
    at com.android.builder.internal.testing.SimpleTestCallable.call(SimpleTestCallable.java:52)
    at java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1424)
    at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
    at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
    at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
    at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)

1 个答案:

答案 0 :(得分:2)

而不是

  - adb wait-for-device

使用

  - android-wait-for-emulator

android-wait-for-emulator脚本不仅等待设备,还等待启动动画太完整。