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

通过YML脚本生成Android Release APK失败求助

问题描述

在Windows机器上,通过Android Studio GUI和本地CMD命令行可正常生成Release APK,但使用GitLab Runner的YML脚本构建时失败,报错核心为Google Play Services Cast相关依赖的资源编译找不到指定文件。

报错信息

> Task :app:processReleaseMainManifest
[com.google.android.gms:play-services-tagmanager:12.0.1] C:\Windows\System32\config\systemprofile\.gradle\caches\transforms-3\59903d787d40edbded5d0ceb720c9856\transformed\jetified-play-services-tagmanager-12.0.1\AndroidManifest.xml Warning:
    Package name 'com.google.android.gms.tagmanager' used in: com.google.android.gms:play-services-tagmanager:12.0.1, com.google.android.gms:play-services-tagmanager-api:12.0.1.
C:\GitLab-Runner\builds\ks7wyRV9\0\buildprocess\spectoapk\app\src\main\AndroidManifest.xml:28:5-65 Warning:
    Element uses-permission#android.permission.VIBRATE at AndroidManifest.xml:28:5-65 duplicated with element declared at AndroidManifest.xml:22:5-66
> Task :app:processReleaseManifest
> Task :communicator:compileReleaseLibraryResources
> Task :app:processReleaseManifestForPackage
> Task :specto:compileReleaseLibraryResources
> Task :app:extractProguardFiles
> Task :communicator:bundleLibResRelease
> Task :specto:bundleLibCompileToJarRelease
> Task :app:processReleaseResources FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:processReleaseResources'.
> Could not resolve all files for configuration ':app:releaseRuntimeClasspath'.
   > Failed to transform play-services-cast-framework-12.0.1.aar (com.google.android.gms:play-services-cast-framework:12.0.1) 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\5364af0121771b691531e78f2f9a3c16\transformed\jetified-play-services-cast-framework-12.0.1.
         > Android resource compilation failed
           ERROR:AAPT: C:\Windows\System32\config\systemprofile\.gradle\caches\transforms-3\8635cf2c80352829dcd09901c7b21377\transformed\com.google.android.gms.cast.framework: error: The system cannot find the file specified. (2).
           
               
   > Failed to transform play-services-cast-12.0.1.aar (com.google.android.gms:play-services-cast:12.0.1) 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\c144de37d49f3842b4e142ad74da822b\transformed\jetified-play-services-cast-12.0.1.
         > Android resource compilation failed
           ERROR:AAPT: C:\Windows\System32\config\systemprofile\.gradle\caches\transforms-3\f0288fa25f3e4abb12b0e471975b9ed0\transformed\com.google.android.gms.cast: error: The system cannot find the file specified. (2).
           
               
   > Failed to transform play-services-cast-12.0.1.aar (com.google.android.gms:play-services-cast:12.0.1) 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\c144de37d49f3842b4e142ad74da822b\transformed\jetified-play-services-cast-12.0.1.
         > Android resource compilation failed
           ERROR:AAPT: C:\Windows\System32\config\systemprofile\.gradle\caches\transforms-3\f0288fa25f3e4abb12b0e471975b9ed0\transformed\com.google.android.gms.cast: error: The system cannot find the file specified. (2).

已尝试的无效操作

  • 升级及降级JDK版本
  • 删除并重新下载Gradle缓存
  • 切换Android Studio至Bumble Bee版本及最新的Iguna版本

解决方案

1. 调整GitLab Runner运行权限

Windows下GitLab Runner默认以Local System账户运行,该账户对C:\Windows\System32\config\systemprofile\.gradle目录的访问权限可能受限:

  • 打开GitLab Runner服务属性,切换到Log On选项卡
  • 选择This account,使用拥有管理员权限的本地账户或域账户登录
  • 重启GitLab Runner服务

2. 自定义Gradle缓存路径

避免使用系统默认目录,在YML脚本中指定项目内的缓存路径:

variables:
  GRADLE_USER_HOME: "${CI_PROJECT_DIR}/.gradle"

确保Runner工作目录有足够读写权限。

3. 强制清理缓存并重新构建

在YML构建步骤中添加清理和无缓存构建命令:

script:
  - ./gradlew clean
  - ./gradlew --no-build-cache --no-configure-on-demand assembleRelease

4. 升级Google Play Services依赖版本

当前使用的12.0.1版本过于老旧,存在兼容性问题,在app/build.gradle中升级至稳定新版本:

dependencies {
    implementation 'com.google.android.gms:play-services-cast:21.0.0'
    implementation 'com.google.android.gms:play-services-cast-framework:21.0.0'
    implementation 'com.google.android.gms:play-services-tagmanager:21.0.1'
}

同步项目后重新构建。

5. 校验AAPT2与Gradle插件兼容性

确保AAPT2版本与Gradle插件匹配,在gradle.properties中启用AAPT2:

android.enableAapt2=true

或在app/build.gradle中指定兼容的构建工具版本:

android {
    buildToolsVersion "34.0.0"
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.28 23:31:08