android - 将 Gradle 升级到 v2.8 后 Travis 未通过 Findbugs

标签 android android-gradle-plugin build.gradle travis-ci

我刚刚将我的 gradle 从版本 2.2 更新到最新的 2.8。我在 2.2 版上使用 findbugs 时没有遇到任何问题。

我正在开发一个包含两个模块的 Android 项目。为了在两个模块中使用查找错误,我在根目录的主 build.gradle 文件上进行了以下配置。

configure(allprojects) {
    apply plugin: 'findbugs'

    task findbugs(type: FindBugs) {
        ignoreFailures = false
        effort = "max"

        classes = fileTree('build/intermediates/classes/')
        source = fileTree('src/main/java')
        classpath = files()

        excludeFilter = file("exclude.xml")

        reportLevel = "high"
        reports {
            xml.enabled = false
            html.enabled = true
        }
    }
}

当我在本地计算机上运行 ./gradlew findbugs 时,一切正常并且构建成功,但是当我将 PR 推送到 Github 并且 Trivis 尝试构建时,我收到错误:

:findbugs UP-TO-DATE
:passenger-app:findbugs
:passenger-sdk:findbugs FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':passenger-sdk:findbugs'.
> FindBugs rule violations were found. See the report at: file:///home/travis/build/project-name/passenger-android/passenger-sdk/build/reports/findbugs/findbugs.html

我真的很困惑为什么我的本地机器上没有问题而 Travis 显示错误!我尝试在 Travis 上打印 findbugs.html 内容,但权限被拒绝:(

我使用的是 java 1.8,而 Travis 使用的是 1.7。问题与此有关吗?谢谢


更新:

为了在 Trivis 上打印 findbugs.html 的内容,我创建了一个 print_findbugs.sh,这就是它的内容。

#!/usr/bin/env bash

echo '**********************'
echo '*** Print Findbugs ***'
echo '**********************'
echo file:///home/travis/build/company/passenger-android/passenger-sdk/build/reports/findbugs/findbugs.html

然后我在 .travis.yml 文件中设置 sudo true 。我在这个文件中拥有什么。

sudo: true
language: android
android:
  components:
    - build-tools-23.0.1
    - android-23
    - extra-android-support
    - extra-google-google_play_services
    - extra-google-m2repository
    - extra-android-m2repository

env:
  global:
// some settings are there


before_cache:
  # Delete the gradle lock file which forces creation of a new build cache
  - rm ~/.gradle/caches/modules-2/modules-2.lock

cache:
  directories:
  - ~/.gradle

before_script:
  # Overwrite the keystore if it is a pull request
  - ./before_script.sh

script:
  # Override Travis default script to not run connectedCheck until this bug is fixed:
  # https://code.google.com/p/android/issues/detail?id=59592
  - ./gradlew clean build findbugs -PdisablePreDex
  - ./print_findbugs.sh

before_deploy:
  # Clean up the output folder
  # Link up the new builds into individual html files
  - ./before_deploy.sh

after_deploy:
  # Upload to...

最后是我的 travis 打印:

:findbugs UP-TO-DATE
:passenger-app:findbugs
:passenger-sdk:findbugs
FindBugs rule violations were found. See the report at: file:///home/travis/build/company/passenger-android/passenger-sdk/build/reports/findbugs/findbugs.html
BUILD SUCCESSFUL
Total time: 8 mins 9.966 secs
The command "./gradlew clean build findbugs -PdisablePreDex" exited with 0.
 $ ./print_findbugs.sh
/home/travis/build.sh: line 41: ./print_findbugs.sh: Permission denied
The command "./print_findbugs.sh" exited with 126.
before_cache
$ rm ~/.gradle/caches/modules-2/modules-2.lock
cache.2
Done. Your build exited with 1.

最佳答案

我不使用它,我需要有关被拒绝的权限的更多信息。

Html 报告

过去,我使用Travis-ci打印html报告,point 5 here 。我使用 apt-get 下载了 lynx(现在不可能使用容器基础设施和 sudo: false)并转换并打印报告。

before_script:   
  # - echo 'LOGCAT'   
  # Check logcat debug output: http://developer.android.com/tools/help/logcat.html
  # Check debugging log: http://developer.android.com/tools/debugging/debugging-log.html
  # Comment the lines belows to debug output and redirect it to a file. Custom tags for your app.
  - adb -e logcat *:W | tee logcat.log > /dev/null 2>&1 &

after_failure:
  # - echo 'FAILURE'
  # Check apt configuration: http://docs.travis-ci.com/user/ci-environment/#apt-configuration
  # Comment out the lines below to show log about tests with app name customized on exports section.
  - sudo apt-get install -qq lynx
  - export MOD_NAME=yourappmodulename
  - export LOG_DIR=${TRAVIS_BUILD_DIR}/${MOD_NAME}/build/outputs/reports/androidTests/connected/
  - lynx --dump ${LOG_DIR}com.android.builder.testing.ConnectedDevice.html > myConnectedDevice.log
  - lynx --dump ${LOG_DIR}com.android.builder.testing.html > myTesting.log
  - for file in *.log; do echo "$file"; echo "====================="; cat "$file"; done || true

Xml 报告

可用于遗留基础设施和基于容器的基础设施。

我听说您可以像这样启用 xml 报告:

    reports {
        xml.enabled = true
        html.enabled = true
    }

您可以使用 cat 轻松在 Travis-ci 上打印 xml 报告 here :

  - cat ${TRAVIS_BUILD_DIR}/ui/espresso/*/app/build/outputs/androidTest-results/connected/* # logs

添加 * 将包含此时的所有子文件夹。

您需要首先在本地找到 xml 报告的文件夹,在我的例子中,它与 html 的文件夹不同,然后将如下内容添加到您的 travis.yml 文件中:

after_failure:
  - cat /home/travis/build/*/passenger-android/passenger-sdk/build/reports/findbugs/*

这并不能解决您的问题,但可能有助于找到原因。

更新:

我建议您先尝试使用cat和没有脚本的xml版本。

关于权限问题的一个很好的解释here以及如何解决making the file executable :

before_script:
 - chmod +x yourscript

更新2:

解决权限被拒绝问题的更好方法已解释here

使用它并提交更改:

git update-index --chmod=+x yourscript

关于android - 将 Gradle 升级到 v2.8 后 Travis 未通过 Findbugs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33336564/

相关文章:

Android Gradle Multidex - 无法最小化 classes.dex,始终包含最大引用

gradle - 将FMPP与Gradle一起使用

Android Gradle 无法构建也无法解析 R

java - 在 Cordova 中添加 android 平台时,请安装 android target 19(android 最新的 sdk)

android - 如何检查我的应用程序是否在 android 中运行(不是作为服务)?

android - 更改 Android 日历 View 的样式

java - 即使没有启用互联网,isProviderEnabled(LocationManager.NETWORK_PROVIDER) 也会返回 true

gradle - 创建包含多个任务的Gradle任务

android-studio - 如何在Android Studio中使用Gradle的按需配置功能

android - 检查 AAR 元数据值时发现一个或多个问题 :