5

我不确定发生了什么,过去在 Azure Devops 中使用我们的管道构建的一切都很好。

但就在最近,我们的每个构建都在 zipaligning 上失败了...... APK zipaligns 并在使用 Android Studio IDE 时构建得很好,但它在 Azure Devops 管道中失败了。

这是 Azure 中 zipalign 的开始:

Starting: AndroidSigning
==============================================================================
Task         : Android signing
Description  : Sign and align Android APK files
Version      : 3.176.0
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/build/android-signing
==============================================================================
"C:\Program Files (x86)\Android\android-sdk\build-tools\29.0.2\zipalign.exe" -v 4 D:\a\1\s\app\build\outputs\apk\release\app-release-unsigned.apk.unaligned D:\a\1\s\app\build\outputs\apk\release\app-release-unsigned.apk
Verifying alignment of D:\a\1\s\app\build\outputs\apk\release\app-release-unsigned.apk (4)...

这是最后的失败消息:

Verification FAILED
##[error]Error: The process 'C:\Program Files (x86)\Android\android-sdk\build-tools\29.0.2\zipalign.exe' failed with exit code 1

最后,这是我们管道 YAML 的上下文:

trigger:
- master

pool:
  vmImage: 'windows-latest'

steps:
- task: Gradle@2
  inputs:
    workingDirectory: ''
    gradleWrapperFile: 'gradlew'
    gradleOptions: '-Xmx5120m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8'
    publishJUnitResults: false
    testResultsFiles: '**/TEST-*.xml'
    tasks: 'assembleRelease'

- task: AndroidSigning@3
  inputs:
    apkFiles: '**/*.apk'
    apksign: true
    apksignerFile: C:\Program Files (x86)\Android\android-sdk\build-tools\29.0.2\apksigner.bat
    apksignerKeystoreFile: 'keystore.jks'
    apksignerKeystorePassword: '$(jarsignerKeystorePassword)'
    apksignerKeystoreAlias: 'alias'
    apksignerKeyPassword: '$(jarsignerKeyPassword)'
    apksignerArguments: --out $(Build.SourcesDirectory)/app/build/outputs/apk/release/app.apk
    zipalign: true
    zipalignFile: C:\Program Files (x86)\Android\android-sdk\build-tools\29.0.2\zipalign.exe

任何帮助将不胜感激!

编辑:当设置为 AndroidSigning@2(jarsigner 而不是 apksigner)时,这是构建失败发布工件的调试日志

2020-11-02T15:49:43.9428841Z ##[debug]Evaluating condition for step: 'PublishBuildArtifacts'
2020-11-02T15:49:43.9430851Z ##[debug]Evaluating: SucceededNode()
2020-11-02T15:49:43.9431429Z ##[debug]Evaluating SucceededNode:
2020-11-02T15:49:43.9432781Z ##[debug]=> True
2020-11-02T15:49:43.9433320Z ##[debug]Result: True
2020-11-02T15:49:43.9433928Z ##[section]Starting: PublishBuildArtifacts
2020-11-02T15:49:43.9558720Z ==============================================================================
2020-11-02T15:49:43.9559237Z Task         : Publish build artifacts
2020-11-02T15:49:43.9559565Z Description  : Publish build artifacts to Azure Pipelines or a Windows file share
2020-11-02T15:49:43.9559869Z Version      : 1.158.3
2020-11-02T15:49:43.9560103Z Author       : Microsoft Corporation
2020-11-02T15:49:43.9560457Z Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/publish-build-artifacts
2020-11-02T15:49:43.9560873Z ==============================================================================
2020-11-02T15:49:43.9627178Z ##[debug]Using node path: C:\agents\2.175.2\externals\node\bin\node.exe
2020-11-02T15:49:44.1659280Z ##[debug]agent.TempDirectory=D:\a\_temp
2020-11-02T15:49:44.1690792Z ##[debug]loading inputs and endpoints
2020-11-02T15:49:44.1701762Z ##[debug]loading ENDPOINT_AUTH_PARAMETER_SYSTEMVSSCONNECTION_ACCESSTOKEN
2020-11-02T15:49:44.1714168Z ##[debug]loading ENDPOINT_AUTH_SCHEME_SYSTEMVSSCONNECTION
2020-11-02T15:49:44.1717582Z ##[debug]loading ENDPOINT_AUTH_SYSTEMVSSCONNECTION
2020-11-02T15:49:44.1719830Z ##[debug]loading INPUT_ARTIFACTNAME
2020-11-02T15:49:44.1721291Z ##[debug]loading INPUT_ARTIFACTTYPE
2020-11-02T15:49:44.1722675Z ##[debug]loading INPUT_PARALLEL
2020-11-02T15:49:44.1723961Z ##[debug]loading INPUT_PARALLELCOUNT
2020-11-02T15:49:44.1725345Z ##[debug]loading INPUT_PATHTOPUBLISH
2020-11-02T15:49:44.1729968Z ##[debug]loading SECRET_JARSIGNERKEYPASSWORD
2020-11-02T15:49:44.1732034Z ##[debug]loading SECRET_JARSIGNERKEYSTOREPASSWORD
2020-11-02T15:49:44.1733774Z ##[debug]loading SECRET_SYSTEM_ACCESSTOKEN
2020-11-02T15:49:44.1739927Z ##[debug]loaded 11
2020-11-02T15:49:44.1753983Z ##[debug]Agent.ProxyUrl=undefined
2020-11-02T15:49:44.1755481Z ##[debug]Agent.CAInfo=undefined
2020-11-02T15:49:44.1756003Z ##[debug]Agent.ClientCert=undefined
2020-11-02T15:49:44.1756464Z ##[debug]Agent.SkipCertValidation=undefined
2020-11-02T15:49:44.1769886Z ##[debug]check path : D:\a\_tasks\PublishBuildArtifacts_2ff763a7-ce83-4e1f-bc89-0ae63477cebe\1.158.3\task.json
2020-11-02T15:49:44.1771713Z ##[debug]adding resource file: D:\a\_tasks\PublishBuildArtifacts_2ff763a7-ce83-4e1f-bc89-0ae63477cebe\1.158.3\task.json
2020-11-02T15:49:44.1772325Z ##[debug]system.culture=en-US
2020-11-02T15:49:44.1792494Z ##[debug]PathtoPublish=D:\a\1\a\app\build\outputs\apk\release\
2020-11-02T15:49:44.1793208Z ##[debug]check path : D:\a\1\a\app\build\outputs\apk\release\
2020-11-02T15:49:44.1821823Z ##[debug]task result: Failed
2020-11-02T15:49:44.1857082Z ##[error]Publishing build artifacts failed with an error: Not found PathtoPublish: D:\a\1\a\app\build\outputs\apk\release\
2020-11-02T15:49:44.1867823Z ##[debug]Processed: ##vso[task.issue type=error;]Publishing build artifacts failed with an error: Not found PathtoPublish: D:\a\1\a\app\build\outputs\apk\release\
2020-11-02T15:49:44.1869433Z ##[debug]Processed: ##vso[task.complete result=Failed;]Publishing build artifacts failed with an error: Not found PathtoPublish: D:\a\1\a\app\build\outputs\apk\release\
2020-11-02T15:49:44.1890809Z ##[section]Finishing: PublishBuildArtifacts
4

1 回答 1

9

因此,在 github azure pipelines task issue thread 上来回折腾之后,我发现通过在我的项目级别 gradle.settings 中将我的 Android gradle 插件从 4.1.0+(它在 4.1.1)更改为 4.0.0 ,天蓝色管道构建将成功完成。

Gradle 本身保持在 6.5 版本,但 Android gradle 插件设置为 4.0.0 以使其构建成功。

然后,另一个人在谷歌问题跟踪器上指出了这个线程: https ://issuetracker.google.com/issues/162117652

从最新的 Android gradle 插件 4.1.0+ 开始,似乎不再需要 zipalign。我猜 Android gradle 插件 4.1.0+ 已经对 apk 进行了 zipalign,因此对 zipalign 的任何后续调用都会显示失败,因为它已经 zipalign。

所以这里的最终解决方案是保留最新版本的 Android gradle 插件(4.1.1)并zipalign: truezipalign: false我的 Azure 管道 AndroidSigning@3 任务中更改。

即使在管道中将 zipalign 设置为 false,您也可以通过运行以下命令来检查以确认您的 APK 是否实际进行了 zipalign:

zipalign -c -v 4 /path/to/app-release.apk.

该命令不会尝试修改文件,而是简单地验证 apk 中的压缩并显示验证是否成功(apk 压缩对齐成功)。

于 2020-11-23T17:26:35.893 回答