如何设置 Android 基于 Visual Studio Team Services

How to set up Android build on Visual Studio Team Services

我对 VSTS 和整个 Microsoft 在线服务平台还很陌生。

我在尝试初始化我们的 VSTS 存储库上的构建时遇到问题。我从下拉菜单中选择了默认的 Android 构建设置,但它不起作用。每次尝试构建时,我都会到达 gradlew build 阶段并收到错误:Error: D:\a\s\gradlew.bat failed with return code: 1

我可以使用 android Studio IDE 构建代码,但我现在需要使用 VSTS。 ` 任何帮助将非常感激。谢谢!

编辑:这是构建的完整日志

2018-07-28T19:23:31.6824618Z ##[section]Starting: gradlew build
2018-07-28T19:23:31.6830050Z ==============================================================================
2018-07-28T19:23:31.6830213Z Task         : Gradle
2018-07-28T19:23:31.6830359Z Description  : Build using a Gradle wrapper script
2018-07-28T19:23:31.6830487Z Version      : 2.137.1
2018-07-28T19:23:31.6830608Z Author       : Microsoft Corporation
2018-07-28T19:23:31.6830766Z Help         : [More Information](https://go.microsoft.com/fwlink/?LinkID=613720)
2018-07-28T19:23:31.6830930Z ==============================================================================
2018-07-28T19:23:33.2899535Z SonarQube analysis is enabled.
2018-07-28T19:23:33.2900156Z Checkstyle analysis is enabled.
2018-07-28T19:23:33.2900406Z FindBugs analysis is enabled.
2018-07-28T19:23:33.2900654Z PMD analysis is enabled.
2018-07-28T19:23:33.2900905Z SYSTEMVSSCONNECTION exists true
2018-07-28T19:23:33.2901941Z [command]C:\Windows\system32\cmd.exe /D /S /C "D:\a\s\gradlew.bat build sonarqube -I D:\a\_tasks\Gradle_8d8eebd8-2b94-4c97-85af-839254cc6da4.137.1\node_modules\codeanalysis-common\checkstyle.gradle -I D:\a\_tasks\Gradle_8d8eebd8-2b94-4c97-85af-839254cc6da4.137.1\node_modules\codeanalysis-common\findbugs.gradle -I D:\a\_tasks\Gradle_8d8eebd8-2b94-4c97-85af-839254cc6da4.137.1\node_modules\codeanalysis-common\pmd.gradle"
2018-07-28T19:24:05.3436260Z Downloading https://services.gradle.org/distributions/gradle-4.6-all.zip
2018-07-28T19:24:29.2233239Z Unzipping C:\Users\VssAdministrator\.gradle\wrapper\dists\gradle-4.6-all\bcst21l2brirad8k2ben1letg\gradle-4.6-all.zip to C:\Users\VssAdministrator\.gradle\wrapper\dists\gradle-4.6-all\bcst21l2brirad8k2ben1letg
2018-07-28T19:25:41.8632779Z Starting a Gradle Daemon (subsequent builds will be faster)

{我们使用的包的一系列下载,由于字数限制省略}

2018-07-28T19:26:20.6092629Z Applying the Checkstyle plugin to project s
2018-07-28T19:26:20.6792218Z Applying the FindBugs plugin to project s
2018-07-28T19:26:20.6792841Z Applying the PMD plugin to all projects
2018-07-28T19:26:23.9485033Z Applying the Checkstyle plugin to project volve
2018-07-28T19:26:23.9621010Z Applying the FindBugs plugin to project volve
2018-07-28T19:26:23.9621425Z Applying the PMD plugin to all projects
2018-07-28T19:26:28.6406403Z support library package not found: android.support.constraint.
2018-07-28T19:26:28.6407012Z support library package not found: android.support.constraint.motion.
2018-07-28T19:26:28.6407656Z support library package not found: android.support.constraint.
2018-07-28T19:26:28.6407994Z support library package not found: android.support.constraint.
2018-07-28T19:26:28.6408285Z support library package not found: android.support.constraint.
2018-07-28T19:26:28.6408525Z support library package not found: android.support.constraint.
2018-07-28T19:26:28.6408784Z support library package not found: android.support.constraint.
2018-07-28T19:26:28.6409785Z support library package not found: android.support.constraint.
2018-07-28T19:26:28.6410031Z support library package not found: android.support.constraint.
2018-07-28T19:26:28.6410325Z support library package not found: android.support.constraint.
2018-07-28T19:26:28.6410567Z support library package not found: android.support.constraint.
2018-07-28T19:26:28.6410830Z support library package not found: android.support.constraint.
2018-07-28T19:26:39.5509667Z Could not find google-services.json while looking in [src/nullnull/debug, src/debug/nullnull, src/nullnull, src/debug, src/nullnullDebug]
2018-07-28T19:26:39.6403284Z registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
2018-07-28T19:26:39.7610924Z registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
2018-07-28T19:26:39.7830309Z Could not find google-services.json while looking in [src/nullnull/release, src/release/nullnull, src/nullnull, src/release, src/nullnullRelease]
2018-07-28T19:26:39.7922748Z registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
2018-07-28T19:26:39.8933520Z registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
2018-07-28T19:26:39.9253837Z 
2018-07-28T19:26:39.9254479Z FAILURE: Build failed with an exception.
2018-07-28T19:26:39.9254716Z 
2018-07-28T19:26:39.9254905Z * What went wrong:
2018-07-28T19:26:39.9255123Z Task 'sonarqube' not found in root project 's'.
2018-07-28T19:26:39.9255269Z 
2018-07-28T19:26:39.9255429Z * Try:
2018-07-28T19:26:39.9255675Z Run gradlew tasks to get a list of available tasks. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
2018-07-28T19:26:39.9255897Z 
2018-07-28T19:26:39.9256078Z * Get more help at https://help.gradle.org
2018-07-28T19:26:39.9256222Z 
2018-07-28T19:26:39.9256413Z BUILD FAILED in 2m 49s
2018-07-28T19:26:40.5195018Z Error: D:\a\s\gradlew.bat failed with return code: 1
2018-07-28T19:26:40.5195970Z     at ChildProcess.<anonymous> (D:\a\_tasks\Gradle_8d8eebd8-2b94-4c97-85af-839254cc6da4.137.1\node_modules\vsts-task-lib\toolrunner.js:569:30)
2018-07-28T19:26:40.5196934Z     at emitTwo (events.js:106:13)
2018-07-28T19:26:40.5197445Z     at ChildProcess.emit (events.js:191:7)
2018-07-28T19:26:40.5198292Z     at maybeClose (internal/child_process.js:886:16)
2018-07-28T19:26:40.5198771Z     at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
2018-07-28T19:26:40.6483964Z ##[warning]No test result files matching D:\a\s\**\TEST-*.xml were found, so publishing JUnit test results is being skipped.
2018-07-28T19:26:40.6494902Z ##[error]Error: D:\a\s\gradlew.bat failed with return code: 1
2018-07-28T19:26:40.6541754Z ##[section]Finishing: gradlew build

您可以使用 Android 构建模板 在 VSTS 中构建您的 android 项目。

Gradle任务的详细配置如下:

  • Gradle 包装器:gradlew 文件的相对路径
  • 工作目录:gradlew 文件所在的同一目录。它默认使用 $(Build.SourcesDirectory) 目录。
  • 任务:构建

比如android项目的文件结构为intro_android_demogradlew文件在repo根目录),那么Gradle任务配置应如下所示: