CircleCI 2.0 Android构建始终失败

时间:2018-09-17 20:42:36

标签: android docker circleci gradlew kapt

我在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

渐变包装版本如下。

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的确切顺序创建了以下八个变量。

  • 免费的AmazonDebug
  • 免费的AmazonRelease
  • 免费的GoogleDebug
  • 免费的GoogleRelease
  • 付费AmazonDebug
  • 付费AmazonRelease
  • paidGoogleDebug
  • paidGoogleRelease

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

  • kaptFreeAmazonDebugKotlin执行无错误。
  • kaptFreeAmazonReleaseKotlin失败,并显示以下堆栈跟踪信息,但不会突然终止该构建。
  

使用Kotlin编译守护程序进行的编译未成功java.rmi.UnmarshalException:解组返回报头时出错;嵌套的   例外是:           java.io.EOFException           在sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:236)           在sun.rmi.server.UnicastRef.invoke(UnicastRef.java:161)           在java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:227)           在java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:179)           在com.sun.proxy。$ Proxy106.compile(未知来源)           在org.jetbrains.kotlin.compilerRunner.GradleCompilerRunner.nonIncrementalCompilationWithDaemon(GradleKotlinCompilerRunner.kt:256)中           在org.jetbrains.kotlin.compilerRunner.GradleCompilerRunner.compileWithDaemon(GradleKotlinCompilerRunner.kt:219)           在org.jetbrains.kotlin.compilerRunner.GradleCompilerRunner.compileWithDaemonOrFallback(GradleKotlinCompilerRunner.kt:166)           在org.jetbrains.kotlin.compilerRunner.GradleCompilerRunner.compileWithDaemonOrFallback(GradleKotlinCompilerRunner.kt:63)           在org.jetbrains.kotlin.compilerRunner.KotlinCompilerRunner.runCompiler(KotlinCompilerRunner.kt:133)           在org.jetbrains.kotlin.compilerRunner.GradleCompilerRunner.runJvmCompiler(GradleKotlinCompilerRunner.kt:119)           在org.jetbrains.kotlin.gradle.internal.KaptWithKotlincTask.compile(KaptWithKotlincTask.kt:71)           在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处           在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)           在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)           在java.lang.reflect.Method.invoke(Method.java:498)           在org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)           在org.gradle.api.internal.project.taskfactory.StandardTaskAction.doExecute(StandardTaskAction.java:46)           在org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:39)           在org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:26)           在org.gradle.api.internal.AbstractTask $ TaskActionWrapper.execute(AbstractTask.java:801)           在org.gradle.api.internal.AbstractTask $ TaskActionWrapper.execute(AbstractTask.java:768)           在org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter $ 1.run(ExecuteActionsTaskExecuter.java:131)           在org.gradle.internal.operations.DefaultBuildOperationExecutor $ RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:300)处           在org.gradle.internal.operations.DefaultBuildOperationExecutor $ RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:292)处           在org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:174)           在org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:90)           在org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)           在org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:120)处           在org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:99)           在org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:77)           在org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)处           在org.gradle.api.internal.tasks.execution.SkipCachedTaskExecuter.execute(SkipCachedTaskExecuter.java:105)           在org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:59)           在org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)           在org.gradle.api.internal.tasks.execution.ResolveBuildCacheKeyExecuter.execute(ResolveBuildCacheKeyExecuter.java:79)           在org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:59)           在org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:101)处           在org.gradle.api.internal.tasks.execution.FinalizeInputFilePropertiesTaskExecuter.execute(FinalizeInputFilePropertiesTaskExecuter.java:44)           在org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:91)           在org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:62)处           在org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:59)           在org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)           在org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)           在org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)           在org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter $ 1.run(EventFiringTaskExecuter.java:51)           在org.gradle.internal.operations.DefaultBuildOperationExecutor $ RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:300)处           在org.gradle.internal.operations.DefaultBuildOperationExecutor $ RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:292)处           在org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:174)           在org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:90)           在org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)           在org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:46)           在org.gradle.execution.taskgraph.LocalTask​​InfoExecutor.execute(LocalTask​​InfoExecutor.java:42)           在org.gradle.execution.taskgraph.DefaultTaskExecutionGraph $ BuildOperationAwareWorkItemExecutor.execute(DefaultTaskExecutionGraph.java:277)处           在org.gradle.execution.taskgraph.DefaultTaskExecutionGraph $ BuildOperationAwareWorkItemExecutor.execute(DefaultTaskExecutionGraph.java:262)处           在org.gradle.execution.taskgraph.DefaultTaskPlanExecutor $ ExecutorWorker $ 1.execute(DefaultTaskPlanExecutor.java:135)处           在org.gradle.execution.taskgraph.DefaultTaskPlanExecutor $ ExecutorWorker $ 1.execute(DefaultTaskPlanExecutor.java:130)处           在org.gradle.execution.taskgraph.DefaultTaskPlanExecutor $ ExecutorWorker.execute(DefaultTaskPlanExecutor.java:200)处           在org.gradle.execution.taskgraph.DefaultTaskPlanExecutor $ ExecutorWorker.executeWithWork(DefaultTaskPlanExecutor.java:191)处           在org.gradle.execution.taskgraph.DefaultTaskPlanExecutor $ ExecutorWorker.run(DefaultTaskPlanExecutor.java:130)处           在org.gradle.internal.concurrent.ExecutorPolicy $ CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)           在org.gradle.internal.concurrent.ManagedExecutorImpl $ 1.run(ManagedExecutorImpl.java:46)           在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)           在java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:624)           在org.gradle.internal.concurrent.ThreadFactoryImpl $ ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)           在java.lang.Thread.run(Thread.java:748)造成原因:java.io.EOFException           在java.io.DataInputStream.readByte(DataInputStream.java:267)           在sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:222)           ... 65更多编译后无法清除jar缓存,也许守护进程已经关闭:java.rmi.ConnectException:连接被拒绝   主机:127.0.0.1;嵌套的异常是:           java.net.ConnectException:连接被拒绝(连接被拒绝)无法连接到kotlin守护程序。使用后备策略。

  • kaptPaidAmazonDebugKotlin失败,出现上述完全相同的堆栈跟踪,并突然终止了gradle构建。

我尝试了我可能想到的gradle选项和java选项以及docker选项的所有可能组合,并且可以尝试在Internet上找到它,但无济于事。

这些故障仅在具有给定Docker映像的云端CircleCI 2.0中或使用CircleCI CLI发生。 gradle在本地构建是稳定的。

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

2 个答案:

答案 0 :(得分:1)

查看时,可能有几种可能的原因:

  • 您使用了错误的buildToolsVersion,为了使用与API级别build.gradle相匹配的最新版本,甚至可以在27中将其省略。

  • 使用com.android.tools.build:gradle:3.3.0-alpha10值得怀疑。 最好使用稳定版本3,1,4;甚至版本3.2.0仍在beta中。

  

编译后无法清除jar缓存

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

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

答案 1 :(得分:0)

android {
    kapt {
        useBuildCache true
    }

    dexOptions {
        preDexLibraries true
        jumboMode false
    }
}