CircleCI 2.0 Android 构建总是失败

CircleCI 2.0 Android Build always Failing

我在 Android 项目代码库的 CircleCI 2.0 配置中有以下内容。

version: 2

jobs:
    build:

        environment:
            TERM: dumb
            JVM_OPTS: -Xmx4g -Xms2g -XX:MaxPermSize=2g

#     ###### Use these for other Docker Images, if need be ##########
#      ANDROID_SDK_ROOT: /usr/local/android-sdk-linux
#      SDK_MANAGER: $ANDROID_SDK_ROOT/tools/bin/sdkmanager

            GIT_COMMIT_DESC: git log --format=oneline -n 1 $CIRCLE_SHA1

            ANDROID_COMPILE_VERSION: 27
            ANDROID_TARGET_VERSION: 27
            ANDROID_MIN_VERSION: 21
            ANDROID_BUILD_VERSION: 28.0.2
            ANDROID_SUPPORT_VERSION: 27.1.1
            KOTLIN_VERSION: 1.2.70

        working_directory: ~/workSpace

        branches:
          only:
            - develop
            - release/<*>
            - feature/circle_ci_cd
          ignore:
            - bugfix/<*>
            - refactor/<*>

        docker:
          - image: circleci/android:api-$ANDROID_TARGET_VERSION-alpha

#    java:
#      version: oraclejdk8

#     ####### Other Docker Images, if need be ############
#    dependencies:
#      pre:
#        - $SDK_MANAGER --install "tools" && yes | $SDK_MANAGER --licenses
#        - $SDK_MANAGER --install "platforms;android-$ANDROID_TARGET_VERSION" && yes | $SDK_MANAGER --licenses
#        - $SDK_MANAGER --install "build-tools;$ANDROID_BUILD_VERSION" && yes | $SDK_MANAGER --licenses
#        - $SDK_MANAGER --install "platform-tools" && yes | $SDK_MANAGER --licenses
#        - $SDK_MANAGER --install "extras;android;m2repository" && yes | $SDK_MANAGER --licenses
#        - $SDK_MANAGER --install "extras;google;m2repository" && yes | $SDK_MANAGER --licenses
#        - $SDK_MANAGER --install "extras;google;google_play_services" && yes | $SDK_MANAGER --licenses

        steps:
          - checkout

          - run:
              name: "Pull Submodules"
              command: |
                git submodule init
                git submodule sync
                git submodule update --remote

          - run:
              name: "Android SDK Properties"
              command: |
                sed -i "s/compileSdkVersion=*.*/compileSdkVersion=$ANDROID_COMPILE_VERSION/" gradle.properties
                sed -i "s/targetSdkVersion=*.*/targetSdkVersion=$ANDROID_TARGET_VERSION/"  gradle.properties
                sed -i "s/minSdkVersion=*.*/minSdkVersion=$ANDROID_MIN_VERSION/" gradle.properties
                sed -i "s/buildToolsVersion=*.*/buildToolsVersion=$ANDROID_BUILD_VERSION/" gradle.properties
                sed -i "s/supportVersion=*.*/supportVersion=$ANDROID_SUPPORT_VERSION/" gradle.properties
                sed -i "s/kotlinVersion=*.*/kotlinVersion=$KOTLIN_VERSION/" gradle.properties
                sed -i "s/versionCode=*.*/versionCode=${CIRCLE_BUILD_NUM:-1}/" gradle.properties

#      ######## Other Docker Images, if need be ###########
#      - run:
#          name: "Update Android"
#          command: $SDK_MANAGER --update && yes | $SDK_MANAGER --licenses

          - run:
              name: "Clean local.properties"
              command: rm -rf local.properties || true

          - run:
              name: Chmod permissions #if permission for Gradlew Dependencies fail, use this.
              command: chmod +x ./gradlew

          - restore_cache:
              key: jars-{{ checksum "build.gradle" }}-{{ checksum  "app/build.gradle" }}

          - run:
              name: Assemble
              command: ./gradlew clean assemble

          - save_cache:
              paths:
                - ${CIRCLE_WORKING_DIRECTORY}/.gradle
                - ${ANDROID_SDK_ROOT}
              key: jars-{{ checksum "build.gradle" }}-{{ checksum  "app/build.gradle" }}
#      - store_artifacts:
#          path: app/build/reports
#          destination: reports
#      - store_test_results:
#          path: app/build/test-results
# See https://circleci.com/docs/2.0/deployment-integrations/ for deploy examples

gradle.properties 文件中几乎没有其他属性

org.gradle.jvmargs=-Xms2g -Xmx4g -XX:MaxPermSize=2g -XX:+HeapDumpOnOutOfMemoryError -XX:ReservedCodeCacheSize=2g -Dfile.encoding=UTF-8
org.gradle.configureondemand=false
org.gradle.caching=true
org.gradle.daemon=false
org.gradle.parallel=false
kotlin.incremental=false
kotlin.compiler.execution.strategy=in-process
android.enableBuildCache=true
android.enableR8=true

Gradle封装版本如下

https\://services.gradle.org/distributions/gradle-4.10.1-all.zip

Gradle Android 插件。

'com.android.tools.build:gradle:3.3.0-alpha10'

以下是构建变体配置。

flavorDimensions "product", "store"

productFlavors {
    free { dimension "product" }
    paid { dimension "product" }
    google { dimension "store" }
    amazon { dimension "store" }
}

开发机器是 MacOS High Sierra:10.13.6、3.5 GHz Intel Core i5 CPU、32 GB 2400 MHz DDR4 RAM。

事情是这样的。

构建变体的顺序是按时间顺序排列的,根据给定的风味维度,因此以下八个是由 gradle 按确切顺序创建的。

每个构建变体都有一个任务依赖列表。 基于任务依赖性,这就是正在发生的事情。

Compilation with Kotlin compile daemon was not successful java.rmi.UnmarshalException: Error unmarshaling return header; nested exception is: java.io.EOFException at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:236) at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:161) at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:227) at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:179) at com.sun.proxy.$Proxy106.compile(Unknown Source) at org.jetbrains.kotlin.compilerRunner.GradleCompilerRunner.nonIncrementalCompilationWithDaemon(GradleKotlinCompilerRunner.kt:256) at org.jetbrains.kotlin.compilerRunner.GradleCompilerRunner.compileWithDaemon(GradleKotlinCompilerRunner.kt:219) at org.jetbrains.kotlin.compilerRunner.GradleCompilerRunner.compileWithDaemonOrFallback(GradleKotlinCompilerRunner.kt:166) at org.jetbrains.kotlin.compilerRunner.GradleCompilerRunner.compileWithDaemonOrFallback(GradleKotlinCompilerRunner.kt:63) at org.jetbrains.kotlin.compilerRunner.KotlinCompilerRunner.runCompiler(KotlinCompilerRunner.kt:133) at org.jetbrains.kotlin.compilerRunner.GradleCompilerRunner.runJvmCompiler(GradleKotlinCompilerRunner.kt:119) at org.jetbrains.kotlin.gradle.internal.KaptWithKotlincTask.compile(KaptWithKotlincTask.kt:71) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73) at org.gradle.api.internal.project.taskfactory.StandardTaskAction.doExecute(StandardTaskAction.java:46) at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:39) at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:26) at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:801) at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:768) at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.run(ExecuteActionsTaskExecuter.java:131) at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:300) at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:292) at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:174) at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:90) at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31) at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:120) at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:99) at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:77) at org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51) at org.gradle.api.internal.tasks.execution.SkipCachedTaskExecuter.execute(SkipCachedTaskExecuter.java:105) at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:59) at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54) at org.gradle.api.internal.tasks.execution.ResolveBuildCacheKeyExecuter.execute(ResolveBuildCacheKeyExecuter.java:79) at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:59) at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:101) at org.gradle.api.internal.tasks.execution.FinalizeInputFilePropertiesTaskExecuter.execute(FinalizeInputFilePropertiesTaskExecuter.java:44) at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:91) at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:62) at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:59) at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54) at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43) at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34) at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.run(EventFiringTaskExecuter.java:51) at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:300) at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:292) at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:174) at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:90) at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31) at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:46) at org.gradle.execution.taskgraph.LocalTaskInfoExecutor.execute(LocalTaskInfoExecutor.java:42) at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareWorkItemExecutor.execute(DefaultTaskExecutionGraph.java:277) at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareWorkItemExecutor.execute(DefaultTaskExecutionGraph.java:262) at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$ExecutorWorker.execute(DefaultTaskPlanExecutor.java:135) at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$ExecutorWorker.execute(DefaultTaskPlanExecutor.java:130) at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$ExecutorWorker.execute(DefaultTaskPlanExecutor.java:200) at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$ExecutorWorker.executeWithWork(DefaultTaskPlanExecutor.java:191) at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$ExecutorWorker.run(DefaultTaskPlanExecutor.java:130) at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63) at org.gradle.internal.concurrent.ManagedExecutorImpl.run(ManagedExecutorImpl.java:46) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55) at java.lang.Thread.run(Thread.java:748) Caused by: java.io.EOFException at java.io.DataInputStream.readByte(DataInputStream.java:267) at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:222) ... 65 more Unable to clear jar cache after compilation, maybe daemon is already down: java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested exception is: java.net.ConnectException: Connection refused (Connection refused) Could not connect to kotlin daemon. Using fallback strategy.

我已经尝试了所有可能的gradle选项和java选项以及我能想到的docker选项的组合,我可以尝试在互联网上找到,但是无济于事。

这些故障仅发生在云上的 CircleCI 2.0 或 CircleCI CLI 中,使用给定的 Docker-image。 gradle 本地构建稳定。

任何指向解决方案的指针都将不胜感激。

审核时,有几种可能的原因:

  • 你用错了buildToolsVersion,甚至可以在build.gradle中省略——为了使用最新版本匹配API级别27.

  • 使用 com.android.tools.build:gradle:3.3.0-alpha10 是有问题的。 最好使用稳定版 3,1,4;甚至版本 3.2.0 目前仍在 beta.

Unable to clear jar cache after compilation

^ 这几乎暗示了文件系统冲突(因为下一个任务已经访问它)。

检查 build 目录 - 并相应地重新定义 productFlavors,以解决该问题。

android {
    kapt {
        useBuildCache true
    }

    dexOptions {
        preDexLibraries true
        jumboMode false
    }
}