Android 当我使用 Jenkins 构建时构建总是失败

Android build fails always when I build using Jenkins

当我尝试使用 jenkins 构建我的 android 项目时,构建总是失败。但是当我通过 android studio 构建时它成功了。

我的项目级别build.gradle代码如下

buildscript {
    repositories {
        jcenter()
        google()
        maven { url 'https://maven.fabric.io/public' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath 'com.novoda:bintray-release:0.5.0'
        classpath 'me.tatarka:gradle-retrolambda:3.5.0'
        classpath 'com.google.gms:google-services:4.0.1'
        classpath 'io.fabric.tools:gradle:1.+'
    }
}
allprojects {
    repositories {
        jcenter()
        maven {
            url "http://dl.bintray.com/schibstedspain/maven"
        }
        maven {
            url 'https://esri.bintray.com/arcgis'
        }
        google()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

模块级别build.gradle如下

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

repositories {
    maven { url 'https://maven.fabric.io/public' }
    mavenCentral()
}
android {
    compileSdkVersion 28
    buildToolsVersion '28.0.3'
    defaultConfig {
        applicationId "com.example.demoapp"
        versionName "1.0.0.6"
        minSdkVersion 19
        targetSdkVersion 28
        versionCode 1
        multiDexEnabled true
        vectorDrawables.useSupportLibrary = true
    }
    packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/license.txt'
    }
    flavorDimensions "demoapp"
    productFlavors {
        localdev {
            manifestPlaceholders = [
                    appIcon: "@mipmap/ic_launcher_local_dev"
            ]
        }
        dev {
            manifestPlaceholders = [
                    appIcon: "@mipmap/ic_launcher_dev"
            ]
        }
    }
    buildTypes {
        release {
            debuggable false
            minifyEnabled false
            shrinkResources false
            jniDebuggable false
            zipAlignEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    dexOptions {
        javaMaxHeapSize "4g"
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    // Android Support libraries
    def supportVersion = '28.0.0'
    implementation "com.android.support:appcompat-v7:$supportVersion"
    implementation "com.android.support:design:$supportVersion"
    implementation 'com.android.support:multidex:1.0.3'
    implementation "com.android.support:cardview-v7:$supportVersion"
    implementation "com.android.support:support-v4:$supportVersion"
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation "com.android.support:support-vector-drawable:$supportVersion"
    implementation "com.android.support:mediarouter-v7:$supportVersion"

    // ArcGIS
    def arcGISVersion = '100.3.0'
    implementation "com.esri.arcgisruntime:arcgis-android:$arcGISVersion"

    // Square libraries
    implementation 'com.squareup.picasso:picasso:2.5.2'
    implementation 'com.squareup.okhttp3:okhttp:3.3.1'
    implementation 'com.squareup.retrofit2:retrofit:2.1.0'
    implementation 'com.squareup.retrofit2:adapter-rxjava:2.0.2'
    implementation 'com.squareup.retrofit2:converter-jackson:2.0.0'
    implementation 'io.reactivex:rxandroid:1.2.1'

    // Google lilbraries
    implementation 'com.google.code.gson:gson:2.8.0'
    implementation 'com.google.android.gms:play-services:11.6.0'
    implementation 'com.google.android.gms:play-services-base:11.6.0'

    // Fabric
    implementation('com.crashlytics.sdk.android:crashlytics:2.9.0@aar') {
        transitive = true
    }
    implementation 'commons-io:commons-io:2.0.1'
    implementation 'com.jakewharton.picasso:picasso2-okhttp3-downloader:1.1.0'
    implementation 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
    implementation 'de.hdodenhof:circleimageview:2.1.0'
    testImplementation 'junit:junit:4.12'
    //Circular imageView hdodenhof
    implementation 'de.hdodenhof:circleimageview:2.2.0'
}
apply plugin: 'com.google.gms.google-services'

以下是我得到的日志。

失败:构建失败,出现异常。

* What went wrong:
Execution failed for task ':app:mergeDevDebugResources'. java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource compilation failed
  Output:  C:\Windows\System32\config\systemprofile\.gradle\caches\transforms-1\files-1.1\appcompat-v7-27.1.1.aard0f08e978f9054bdf191f5dc7a9836\res\drawable-xhdpi-v4\abc_text_select_handle_middle_mtrl_light.png: error: file not found.

  Command: C:\Windows\System32\config\systemprofile\.gradle\caches\transforms-1\files-1.1\aapt2-3.2.1-4818971-windows.jar\d0f8b1c9646d3205e347ca7495d045a1\aapt2-3.2.1-4818971-windows\aapt2.exe compile --no-crunch \
          --legacy \
          -o \
          D:\workspace\technician\app\build\intermediates\res\merged\dev\debug \
          C:\Windows\System32\config\systemprofile\.gradle\caches\transforms-1\files-1.1\appcompat-v7-27.1.1.aard0f08e978f9054bdf191f5dc7a9836\res\drawable-xhdpi-v4\abc_text_select_handle_middle_mtrl_light.png
  Daemon:  AAPT2 aapt2-3.2.1-4818971-windows Daemon #0

* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:mergeDevDebugResources'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:103)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:73)
    at org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)
    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:59)
    at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
    at org.gradle.api.internal.tasks.execution.ResolveBuildCacheKeyExecuter.execute(ResolveBuildCacheKeyExecuter.java:66)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:59)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:101)
    at org.gradle.api.internal.tasks.execution.FinalizeInputFilePropertiesTaskExecuter.execute(FinalizeInputFilePropertiesTaskExecuter.java:44)
    at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:91)
    at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:62)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:59)
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
    at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
    at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.run(DefaultTaskGraphExecuter.java:256)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:249)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:238)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:123)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access0(DefaultTaskPlanExecutor.java:79)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.execute(DefaultTaskPlanExecutor.java:104)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.execute(DefaultTaskPlanExecutor.java:98)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:663)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:597)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:98)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
    at org.gradle.internal.concurrent.ManagedExecutorImpl.run(ManagedExecutorImpl.java:46)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
Caused by: org.gradle.internal.UncheckedException: java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource compilation failed
Output:  C:\Windows\System32\config\systemprofile\.gradle\caches\transforms-1\files-1.1\appcompat-v7-27.1.1.aard0f08e978f9054bdf191f5dc7a9836\res\drawable-xhdpi-v4\abc_text_select_handle_middle_mtrl_light.png: error: file not found.

Command: C:\Windows\System32\config\systemprofile\.gradle\caches\transforms-1\files-1.1\aapt2-3.2.1-4818971-windows.jar\d0f8b1c9646d3205e347ca7495d045a1\aapt2-3.2.1-4818971-windows\aapt2.exe compile --no-crunch \
        --legacy \
        -o \
        D:\workspace\technician\app\build\intermediates\res\merged\dev\debug \
        C:\Windows\System32\config\systemprofile\.gradle\caches\transforms-1\files-1.1\appcompat-v7-27.1.1.aard0f08e978f9054bdf191f5dc7a9836\res\drawable-xhdpi-v4\abc_text_select_handle_middle_mtrl_light.png
Daemon:  AAPT2 aapt2-3.2.1-4818971-windows Daemon #0
    at org.gradle.internal.UncheckedException.throwAsUncheckedException(UncheckedException.java:63)
    at org.gradle.internal.UncheckedException.throwAsUncheckedException(UncheckedException.java:40)
    at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:76)
    at org.gradle.api.internal.project.taskfactory.IncrementalTaskAction.doExecute(IncrementalTaskAction.java:50)
    at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:39)
    at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:26)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.run(ExecuteActionsTaskExecuter.java:124)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:113)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:95)
    ... 31 more
Caused by: java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource compilation failed
Output:  C:\Windows\System32\config\systemprofile\.gradle\caches\transforms-1\files-1.1\appcompat-v7-27.1.1.aard0f08e978f9054bdf191f5dc7a9836\res\drawable-xhdpi-v4\abc_text_select_handle_middle_mtrl_light.png: error: file not found.

Command: C:\Windows\System32\config\systemprofile\.gradle\caches\transforms-1\files-1.1\aapt2-3.2.1-4818971-windows.jar\d0f8b1c9646d3205e347ca7495d045a1\aapt2-3.2.1-4818971-windows\aapt2.exe compile --no-crunch \
        --legacy \
        -o \
        D:\workspace\technician\app\build\intermediates\res\merged\dev\debug \
        C:\Windows\System32\config\systemprofile\.gradle\caches\transforms-1\files-1.1\appcompat-v7-27.1.1.aard0f08e978f9054bdf191f5dc7a9836\res\drawable-xhdpi-v4\abc_text_select_handle_middle_mtrl_light.png
Daemon:  AAPT2 aapt2-3.2.1-4818971-windows Daemon #0
    at com.android.ide.common.workers.ExecutorServiceAdapter.close(ExecutorServiceAdapter.kt:56)
    at com.android.build.gradle.internal.aapt.WorkerExecutorResourceCompilationService.close(WorkerExecutorResourceCompilationService.kt:67)
    at com.android.build.gradle.tasks.MergeResources.doFullTaskAction(MergeResources.java:324)
    at com.android.build.gradle.internal.tasks.IncrementalTask.taskAction(IncrementalTask.java:106)
    at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
    ... 41 more
Caused by: com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource compilation failed
Output:  C:\Windows\System32\config\systemprofile\.gradle\caches\transforms-1\files-1.1\appcompat-v7-27.1.1.aard0f08e978f9054bdf191f5dc7a9836\res\drawable-xhdpi-v4\abc_text_select_handle_middle_mtrl_light.png: error: file not found.

Command: C:\Windows\System32\config\systemprofile\.gradle\caches\transforms-1\files-1.1\aapt2-3.2.1-4818971-windows.jar\d0f8b1c9646d3205e347ca7495d045a1\aapt2-3.2.1-4818971-windows\aapt2.exe compile --no-crunch \
        --legacy \
        -o \
        D:\workspace\technician\app\build\intermediates\res\merged\dev\debug \
        C:\Windows\System32\config\systemprofile\.gradle\caches\transforms-1\files-1.1\appcompat-v7-27.1.1.aard0f08e978f9054bdf191f5dc7a9836\res\drawable-xhdpi-v4\abc_text_select_handle_middle_mtrl_light.png
Daemon:  AAPT2 aapt2-3.2.1-4818971-windows Daemon #0
    at com.android.builder.internal.aapt.v2.Aapt2DaemonImpl.doCompile(Aapt2DaemonImpl.kt:142)
    at com.android.builder.internal.aapt.v2.Aapt2Daemon.compile(Aapt2Daemon.kt:81)
    at com.android.builder.internal.aapt.v2.Aapt2DaemonManager$LeasedAaptDaemon.compile(Aapt2DaemonManager.kt:170)
    at com.android.build.gradle.internal.res.Aapt2CompileWithBlameRunnable$run.invoke(Aapt2CompileWithBlameRunnable.kt:37)
    at com.android.build.gradle.internal.res.Aapt2CompileWithBlameRunnable$run.invoke(Aapt2CompileWithBlameRunnable.kt:28)
    at com.android.build.gradle.internal.res.namespaced.Aapt2DaemonManagerService.useAaptDaemon(Aapt2DaemonManagerService.kt:71)
    at com.android.build.gradle.internal.res.namespaced.Aapt2DaemonManagerService.useAaptDaemon$default(Aapt2DaemonManagerService.kt:69)
    at com.android.build.gradle.internal.res.Aapt2CompileWithBlameRunnable.run(Aapt2CompileWithBlameRunnable.kt:34)
    at com.android.ide.common.workers.ExecutorServiceAdapter$submit$submission.run(ExecutorServiceAdapter.kt:39)


* Get more help at https://help.gradle.org

BUILD FAILED in 18s
18 actionable tasks: 16 executed, 2 up-to-date

由于配置问题,构建扫描未发布。

尚未同意 Gradle 服务条款。

要同意 Gradle 服务条款,请在根项目的配置中包含以下内容: buildScan { termsOfServiceUrl = 'https://gradle.com/terms-of-service'; termsOfServiceAgree = 'yes' }

更多信息,请参阅https://gradle.com/scans/help/plugin-terms-of-service

或者,如果您使用的是 Gradle Enterprise,请指定服务器位置。 更多信息,请参阅https://gradle.com/scans/help/plugin-enterprise-config

构建步骤 'Invoke Gradle script' 将构建结果更改为 FAILURE 构建步骤 'Invoke Gradle script' 将构建标记为失败 已完成:失败

使用 jenkins 构建时似乎找不到某些文件。这可能是由于运行 Jenkins 服务的用户。您可以尝试通过以下步骤更改 jenkins 服务的用户:

  1. 打开 Windows 上的管理工具 > 服务 window 服务器。
  2. 停止 Jenkins 服务。
  3. 打开“属性”>“登录”对话框。
  4. 将服务用户帐户更改为目标用户帐户。
  5. 启动 Jenkins 服务。