2

我最近更新了我的项目以从 Android Studio 3.3 构建,其中涉及进行以下更改(在 Android Studio 启动时提示):

build.gradle 依赖:

classpath 'com.android.tools.build:gradle:3.3.0'

毕业包装:

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

当尝试使用 Google 地图进行同步时,这会在功能模块中产生许多错误。我正在使用 16.0.0 版的 play-services-maps:

implementation "com.google.android.gms:play-services-maps:16.0.0"

尝试同步 gradle 时出现的错误是:

ERROR: Unable to resolve dependency for ':featureModule@flavorDebugFeature/compileClasspath': Could not resolve androidx.annotation:annotation:1.0.0.

ERROR: Unable to resolve dependency for ':featureModule@flavorDebugFeature/compileClasspath': Could not resolve androidx.annotation:annotation:1.0.1.

ERROR: Unable to resolve dependency for ':featureModule@flavorDebugFeature/compileClasspath': Could not resolve androidx.core:core:1.0.0.

ERROR: Unable to resolve dependency for ':featureModule@flavorDebugFeature/compileClasspath': Could not resolve androidx.core:core:1.0.1.

对于此模块中的每个可能的风味变体组合,都会重复此操作。

值得指出的是,这个项目几个月前已经迁移到 androidX 并且一直运行良好。

错误的修复是将以下内容添加到该失败模块的 gradle 依赖项中:

implementation "androidx.annotation:annotation:1.0.1"
implementation "androidx.core:core:1.0.1"

然后该应用程序可以正常编译并在设备上运行。完美的。直到我们在项目发布之前尝试在 CI 构建中运行 lint,我们遇到了麻烦,并出现错误消息:

Execution failed for task ':featureModule:lintFlavorDebug'.
> Lint infrastructure error
  Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
... [several lines omitted for brevity]
 Caused by: java.lang.IllegalStateException: Expected task 'processFlavorDebugAndroidTestJavaRes' output files to contain exactly one file, however, it contains no files.
    at org.gradle.api.internal.file.AbstractFileCollection.getSingleFile(AbstractFileCollection.java:65)
    at com.android.build.gradle.internal.variant.BaseVariantData.getJavaResourcesForUnitTesting(BaseVariantData.java:700)
    at com.android.build.gradle.internal.ide.ModelBuilder.createAndroidArtifact(ModelBuilder.java:992)
    at com.android.build.gradle.internal.ide.ModelBuilder.createVariant(ModelBuilder.java:617)
    at com.android.build.gradle.internal.ide.ModelBuilder.buildAndroidProject(ModelBuilder.java:399)
    at com.android.build.gradle.internal.ide.ModelBuilder.buildAll(ModelBuilder.java:212)
    at com.android.tools.lint.gradle.LintGradleExecution.createAndroidProject(LintGradleExecution.java:352)
    at com.android.tools.lint.gradle.LintGradleExecution.analyze(LintGradleExecution.java:85)
    ... 59 more

如果我们删除 2 个新依赖项(加上 Google 地图,这似乎是需要核心和注释库的原因),这个问题就会消失。

我已经在这里和通过 Google 进行了一些搜索,Expected task 'processFlavorDebugAndroidTestJavaRes' output files to contain exactly one file, however, it contains no files.其他人已经看到了异常,他们的解决方案是确保基本 build.gradle 文件具有baseFeature truein 标志defaultConfig,该标志已经存在于我的项目中。

我现在不知道下一步该去哪里解决这个问题。

4

0 回答 0