Gradle 错误:无法将文件转换为匹配属性 jetified

Jim*_*nts 5 android gradle azure-pipelines

我已经建立了一个在 microsoft azure pipelines中运行我的测试的管道。在我的本地机器上,这工作正常,该jetified-libidpmobile-debug.jar文件位于我机器上的 gradle 系统目录中:

/Users/jimclermonts/.gradle/caches/transforms-2/files-2.1/efad9765ab457848824459e0c76abddc/jetified-libidpmobile-debug.jar
Run Code Online (Sandbox Code Playgroud)

这是我的build.gradle:

debugImplementation files('libs/libidpmobile-debug.jar')
Run Code Online (Sandbox Code Playgroud)

据我了解,jetified-libidpmobile-debug.jar是由jetifier从libidpmobile-debug.jar文件中自动创建的。

输出:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:kaptDebugKotlin'.
> Could not resolve all files for configuration ':app:_classStructurekaptDebugKotlin'.
   > Failed to transform file 'jetified-libidpmobile-debug.jar' to match attributes {artifactType=class-structure, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}
      > Execution failed for StructureArtifactTransform: /Users/iosadmin/.gradle/caches/transforms-2/files-2.1/1e14bb7ec832a0c2c967e6c977ddd9b9/jetified-libidpmobile-debug.jar.
         > error in opening zip file
Run Code Online (Sandbox Code Playgroud)

这是我的 azure-pipelines.yml 中组装调试和测试单元测试的部分:

trigger:
- master

pool:
  name: Mobile-Pool

steps:
- task: Gradle@2
  inputs:
    workingDirectory: ''
    gradleWrapperFile: 'gradlew'
    gradleOptions: '-Xmx4096m'
    publishJUnitResults: false
    testResultsFiles: '**/TEST-*.xml'
    tasks: 'assembleDebug testDebugUnitTest'
Run Code Online (Sandbox Code Playgroud)

我尝试了这篇文章、这篇文章和这篇文章中的解决方案,但没有结果。jar 文件有 4mb 大,是代码存储库中的唯一文件,而不是某些 Maven 存储库。

将 Gradle 更新到最新:

classpath 'com.android.tools.build:gradle:4.0.0-beta05'
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
Run Code Online (Sandbox Code Playgroud)

尝试像这样编辑 androidmanifest:

tools:replace="android:appComponentFactory"
android:appComponentFactory="androidx.core.app.CoreComponentFactory">
Run Code Online (Sandbox Code Playgroud)

构建.gradle:

kotlinOptions {
    jvmTarget = '1.8'
}

compileOptions {
    targetCompatibility JavaVersion.VERSION_1_8
    sourceCompatibility JavaVersion.VERSION_1_8
}
Run Code Online (Sandbox Code Playgroud)

Lev*_*SFT 0

从错误来看似乎是数据绑定问题The following options were not recognized by any processor: '[android.databinding.minApi....

您可以尝试将以下行添加到 build.gradle 文件中。

kapt "com.android.databinding:compiler:$gradle_version"

您可以查看以下类似主题以获取更多信息:

Gradle 插件更新并迁移到annotationProcessor 后,Android 数据绑定构建失败

如果启用 Android 数据绑定,则项目失败

希望以上有帮助!