CircleCI - Android Studio项目中未发现SDK位置

3
在尝试在CircleCI上构建项目时,gradle构建期间出现以下错误。这个问题的原因是什么?我正在运行 CircleCI 2.0

失败:构建发生异常。

  • 出了什么问题:配置项目 ':app' 失败。

    未找到SDK位置。在 local.properties 文件中使用 sdk.dir 或使用 ANDROID_HOME 环境变量定义位置。

  • 尝试:运行--stacktrace选项以获取堆栈跟踪。使用 --info 或 --debug 选项运行以获得更多日志输出。

  • 获取更多帮助:https://help.gradle.org

18秒内构建失败,退出代码1

我的config.yml文件如下:

# Java Gradle CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-java/ for more details
#
version: 2
jobs:
  build:
    docker:
      # specify the version you desire here
      - image: circleci/openjdk:8-jdk

      # Specify service dependencies here if necessary
      # CircleCI maintains a library of pre-built images
      # documented at https://circleci.com/docs/2.0/circleci-images/
      # - image: circleci/postgres:9.4

    working_directory: ~/repo

    environment:
      # Customize the JVM maximum heap limit
      JVM_OPTS: -Xmx3200m
      TERM: dumb

    steps:
      - checkout

      # Download and cache dependencies
      - restore_cache:
          keys:
          - v1-dependencies-{{ checksum "build.gradle" }}
          # fallback to using the latest cache if no exact match is found
          - v1-dependencies-

      - run: gradle dependencies

      - save_cache:
          paths:
            - ~/.m2
          key: v1-dependencies-{{ checksum "build.gradle" }}

      # run tests!
      - run: gradle test
2个回答

5

CircleCI 为 Android 提供了一个 示例配置文件,可以处理你遇到的 SDK 问题。我不确定为什么在设置新项目时他们没有展示这个选项。

基本上,在 CircleCI 上设置一个新项目时,你可能选择了 Gradle (Java) 选项。这并没有特定地针对 Android,所以才会报缺少 SDK 的错误。

上面链接的示例配置文件如下(最重要的部分是指定的 Docker 镜像,CircleCI 文档对每一行都有很好的解释):

version: 2
jobs:
  build:
    working_directory: ~/code
    docker:
      - image: circleci/android:api-25-alpha
    environment:
      JVM_OPTS: -Xmx3200m
    steps:
      - checkout
      - restore_cache:
          key: jars-{{ checksum "build.gradle" }}-{{ checksum  
"app/build.gradle" }}
      - run:
          name: Download Dependencies
          command: ./gradlew androidDependencies
      - save_cache:
          paths:
            - ~/.gradle
          key: jars-{{ checksum "build.gradle" }}-{{ checksum  
"app/build.gradle" }}
      - run:
          name: Run Tests
          command: ./gradlew lint test
      - store_artifacts:
          path: app/build/reports
          destination: reports
      - store_test_results:
          path: app/build/test-results

希望您尽快完成建设!


谢谢,这对我有用。 我还得取消文件中权限部分的注释:# - run: # name: Chmod permissions #if permission for Gradlew Dependencies fail, use this. # command: sudo chmod +x ./gradlew - Ilya
对我来说,我遇到了这个错误, 配置错误:发生了2个错误:
  • 解析配置文件时出错:yaml:行17:无法找到预期的“:”
  • 在您的配置文件的“jobs:”部分中找不到名为build的作业要运行。 如果您希望运行工作流,请检查您的配置是否包含一个名为'workflows:'的顶级键。
- Sreedev
嘿 @SreedevR,这听起来像是你的 config.yml 文件可能不正确。你有链接可以让我看一下吗? - Mark

2

我用过这个方法,对我很有效。 最初遇到了索引问题。代码没有被正确地索引。这可能是其他人也会遇到的问题。

version: 2
jobs:
  build:
working_directory: ~/code
docker:
  - image: circleci/android:api-25-alpha
environment:
  JVM_OPTS: -Xmx3200m
steps:
  - checkout
  - restore_cache:
      key: jars-{{ checksum "build.gradle" }}-{{ checksum  "app/build.gradle" }}
  - run:
     name: Chmod permissions #if permission for Gradlew Dependencies fail, use this.
     command: sudo chmod +x ./gradlew
  - run:
      name: Download Dependencies
      command: ./gradlew androidDependencies
  - save_cache:
      paths:
        - ~/.gradle
      key: jars-{{ checksum "build.gradle" }}-{{ checksum  "app/build.gradle" }}
  - run:
      name: Run Tests
      command: ./gradlew lint test
  - store_artifacts:
      path: app/build/reports
      destination: reports
  - store_test_results:
      path: app/build/test-results

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接