在 Azure 中运行 Android 测试:类型不匹配:推断类型是 () -> String?但是字符串?是预料之中的

问题描述 投票:0回答:1

当我运行 Android 项目的 Azure 管道来运行测试时,在 test 步骤期间,两个 gradle 任务失败,compileDebugKotlincompileReleaseKotlin,标题中出现错误,准确指向此 HttpLoggingInterceptor()

private fun getHttpClient(
    ): OkHttpClient {

        val logger = HttpLoggingInterceptor()
        logger.level = HttpLoggingInterceptor.Level.BODY

        val customLoggingInterceptor = CustomLoggingInterceptor(logger)

        return OkHttpClient.Builder()
            .addInterceptor(
                BearerInterceptor { token }
            )
            .addInterceptor(
                customLoggingInterceptor
            )
            .addInterceptor(
                logger
            )
            .connectTimeout(
                CONNECTION_TIMEOUT_IN_SECONDS,
                TimeUnit.SECONDS
            )
            .readTimeout(
                CONNECTION_TIMEOUT_IN_SECONDS,
                TimeUnit.SECONDS
            )
            .build()
    }

当我在本地运行这两个任务时,没有错误。更新了拦截器依赖,本地和azure都使用gradle包装器8.0。

根据评论,这是 yaml 管道:

# Android
# Build your Android project with Gradle.
# Add steps that test, sign, and distribute the APK, save build artifacts, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/android

# Pipeline to run the tests as a precondition to every direct commit / Pull Request to develop/main branches
trigger:
  branches:
    include:
      - develop
      - main

pr:
  branches:
    include:
      - develop
      - main

pool:
  vmImage: 'ubuntu-latest'

resources:
  repositories:
    - repository: my_subrepository
      type: git
      name: TheAzureProject/TheMainRepository

steps:
- checkout: self
- checkout: my_subrepository
  path: s/TheMainRepository/my_subrepository

- task: JavaToolInstaller@0
  displayName: Setup Java 17
  inputs:
    versionSpec: '17'
    jdkArchitectureOption: 'x64'
    jdkSourceOption: 'PreInstalled'

- task: Gradle@3
  displayName: Run Tests
  inputs:
    workingDirectory: 'TheMainRepository'
    gradleWrapperFile: 'TheMainRepository/gradlew'
    gradleOptions: '-Xmx3072m'
    javaHomeOption: 'JDKVersion'
    publishJUnitResults: true
    testResultsFiles: '**/TEST-*.xml'
    tasks: 'test'
android gradle azure-devops android-gradle-plugin okhttp
1个回答
0
投票

找到了原因,原来管道仅使用当前分支用于主项目,它使用git子模块的默认分支(主),因此错误日志指向一个没有意义的地方。 教训:如果项目有 Git 子模块,请确保强制管道也使用这些子模块中的适当分支。 (我发现触发了手动运行,仍在努力将其添加到 yaml 文件中)

© www.soinside.com 2019 - 2024. All rights reserved.