You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Jenkins执行connectedAndroidTest时app:processDebugResources任务失败求助

Jenkins执行Android UI测试时app:processDebugResources失败排查

问题背景

Android Studio中可正常构建项目,但通过Jenkins执行connectedAndroidTest Gradle命令时,反复触发app:processDebugResources失败错误;后续调整Gradle缓存路径、升级Gradle版本后,又出现Manifest文件找不到的新问题。

初始报错信息

执行connectedAndroidTest后输出错误:

Task :app:processDebugResources FAILED   

FAILURE: Build failed with an exception.
  * What went wrong:
Execution failed for task ':app:processDebugResources'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
   > Failed to transform appcompat-1.3.0.aar (androidx.appcompat:appcompat:1.3.0) to match attributes {artifactType=android-compiled-dependencies-resources, org.gradle.category=library, org.gradle.dependency.bundling=external, org.gradle.libraryelements=aar, org.gradle.status=release, org.gradle.usage=java-runtime}.
      > Execution failed for AarResourcesCompilerTransform: C:\Windows\System32\config\systemprofile\.gradle\caches\transforms-3\9398b1795b0a45e239a8370198c80687\transformed\appcompat-1.3.0.
         > Android resource compilation failed
           ERROR:AAPT: C:\Windows\System32\config\systemprofile\.gradle\caches\transforms-3\5b50c60af17e66ade7be3083cf0fe04d\transformed\androidx.appcompat: error: 无法找到指定文件。(2).
           
               
   > Failed to transform appcompat-1.3.0.aar (androidx.appcompat:appcompat:1.3.0) to match attributes {artifactType=android-compiled-dependencies-resources, org.gradle.status=release}.
      > Execution failed for AarResourcesCompilerTransform: C:\Windows\System32\config\systemprofile\.gradle\caches\transforms-3\9398b1795b0a45e239a8370198c80687\transformed\appcompat-1.3.0.
         > Android resource compilation failed
           ERROR:AAPT: C:\Windows\System32\config\systemprofile\.gradle\caches\transforms-3\5b50c60af17e66ade7be3083cf0fe04d\transformed\androidx.appcompat: error: 无法找到指定文件。(2).
           
               
   > Failed to transform core-1.6.0.aar (androidx.core:core:1.6.0) to match attributes {artifactType=android-compiled-dependencies-resources, org.gradle.category=library, org.gradle.dependency.bundling=external, org.gradle.libraryelements=aar, org.gradle.status=release, org.gradle.usage=java-runtime}.
      > Execution failed for AarResourcesCompilerTransform: C:\Windows\System32\config\systemprofile\.gradle\caches\transforms-3\619c06b67a6c841ffa9224727d661a21\transformed\core-1.6.0.
         > Android resource compilation failed
           ERROR:AAPT: C:\Windows\System32\config\systemprofile\.gradle\caches\transforms-3\308760ecdbed89bb153e932d840e53f3\transformed\androidx.core: error: 无法找到指定文件。(2).

项目build.gradle配置

plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'kotlin-kapt'
    id 'kotlin-parcelize'
    id 'com.shazam.fork'
}

apply plugin: 'com.shazam.fork'

android {
    compileSdkVersion 30
    defaultConfig {
        configurations.all {
            resolutionStrategy { force 'androidx.core:core-ktx:1.6.0' }
        }
        applicationId "app.converter" // it's ok, nevermind
        minSdkVersion 30
        //noinspection OldTargetApi
        targetSdkVersion 30
        versionCode 5
        versionName "5"
        testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
        vectorDrawables.useSupportLibrary = true
    }
    compileOptions{
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
        buildFeatures {
            viewBinding true
        }
    }
}

dependencies {
    ....
    //noinspection GradleDependency
    implementation 'androidx.appcompat:appcompat:1.3.0'
   ....

    implementation 'androidx.core:core-ktx:1.6.0'
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

    implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
}

后续尝试及新错误

  1. 添加-g C:\gradle-cache指定Gradle缓存路径后,出现Manifest文件找不到的错误:
22:14:03 * What went wrong:
22:14:03 Execution failed for task ':app:processDebugAndroidTestResources'.
22:14:03 > A failure occurred while executing com.android.build.gradle.internal.res.LinkApplicationAndroidResourcesTask$TaskAction
22:14:03    > Android resource linking failed
22:14:03      C:\Windows\System32\config\systemprofile\AppData\Local\Jenkins\.jenkins\workspace\ConverterKT\app\build\intermediates\packaged_manifests\debugAndroidTest\AndroidManifest.xml: error: failed to load XML file: 无法找到指定文件。(2).
  1. 升级Gradle到7.5后,错误变为同时找不到debug和debugAndroidTest的Manifest文件:
21:01:23 FAILURE: Build completed with 2 failures.
21:01:23 
21:01:23 1: Task failed with an exception.
21:01:23 -----------
21:01:23 * What went wrong:
21:01:23 Execution failed for task ':app:processDebugResources'.
21:01:23 > A failure occurred while executing com.android.build.gradle.internal.res.LinkApplicationAndroidResourcesTask$TaskAction
21:01:23    > Android resource linking failed
21:01:23      C:\Windows\System32\config\systemprofile\AppData\Local\Jenkins\.jenkins\workspace\ConverterKT\app\build\intermediates\packaged_manifests\debug\AndroidManifest.xml: error: failed to load XML file: 无法找到指定文件。(2).
21:01:23 
21:01:23 
21:01:23 * Try:
21:01:23 > Run with --stacktrace option to get the stack trace.
21:01:23 > Run with --info or --debug option to get more log output.
21:01:23 > Run with --scan to get full insights.
21:01:23 ==============================================================================
21:01:23 
21:01:23 2: Task failed with an exception.
21:01:23 -----------
21:01:23 * What went wrong:
21:01:23 Execution failed for task ':app:processDebugAndroidTestResources'.
21:01:23 > A failure occurred while executing com.android.build.gradle.internal.res.LinkApplicationAndroidResourcesTask$TaskAction
21:01:23    > Android resource linking failed
21:01:23      C:\Windows\System32\config\systemprofile\AppData\Local\Jenkins\.jenkins\workspace\ConverterKT\app\build\intermediates\packaged_manifests\debugAndroidTest\AndroidManifest.xml: error: failed to load XML file: 无法找到指定文件。(2).

解决方案

  • 调整Jenkins服务运行账户:Windows下Jenkins默认以Local System Account运行,该账户对系统目录权限有限。打开services.msc找到Jenkins服务,右键属性切换到登录选项卡,选择拥有本地管理员权限的普通账户,重启Jenkins服务。
  • 清理缓存与工作区:在Jenkins任务中添加前置步骤,执行./gradlew clean cleanBuildCache;手动删除Jenkins工作区的build目录、指定的Gradle缓存目录。
  • 更换Gradle缓存路径:将缓存路径指定到普通目录(如D:\Jenkins\gradle-cache),确保该目录已创建且Jenkins账户有读写权限,在Gradle任务中通过-g D:\Jenkins\gradle-cache指定。
  • 检查Android SDK配置:确认Jenkins中配置的Android SDK路径与Android Studio一致,且安装了与项目compileSdkVersion匹配的Build Tools版本(项目用30,需安装Build Tools 30.x)。
  • 移除强制依赖配置:尝试删除defaultConfig中的强制依赖代码,让Gradle自动处理版本依赖:
    // 移除这段配置
    configurations.all {
        resolutionStrategy { force 'androidx.core:core-ktx:1.6.0' }
    }
    

内容的提问来源于stack exchange,提问作者AShX

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.24 15:39:13