造成原因:java.lang.NoSuchMethodException:否这样的方法:org.apache.logging.log4j.util.StackLocator

时间:2018-08-10 16:00:18

标签: android-studio gradle

在将AndroidStudio更新到最新的3.1.x版本后,gradle抱怨annoationProcessors必须单独声明,并建议我在annoationProcessor配置中添加“ org.apache.logging.log4j:log4j-core:2.10.0”。

我添加了它,此运行任务导致以下错误:

run tasks
  :app:transformClassesWithDesugarForAppDebug   11s 442ms

错误:

Caused by: java.lang.NoSuchMethodException: no such method: org.apache.logging.log4j.util.StackLocator.lambda$getCallerClass$3(String,String,Stream)Optional/invokeStatic

Caused by: java.lang.NoSuchFieldError: method resolution failed

我还尝试过使用此功能来禁用注释检查,而不是添加上面的行:

    defaultConfig {
        ...
        javaCompileOptions {
            annotationProcessorOptions {
                includeCompileClasspath false
            }
        }
    }

所有这些都会导致上述相同错误。

我没有将此库添加为依赖项,这意味着它是我要导入的其他库的一部分,但我不确定是哪个。

有没有办法...

  1. 通过Google某个隐藏文档中记录的一些新的魔术配置更改解决此问题吗?
  2. 如果这不是一个选项,请禁用此依赖项,以免惹恼我的项目?
  3. 如何查找使用此库的依赖项,以便代替或更新该依赖项?

DependencyInsight:

  

配置项目:androidlib   publishNonDefault已弃用,不再起作用。所有变体现已发布。   在[src / nullnull / debug,src / debug / nullnull,src / nullnull,src / debug,src / nullnullDebug]中查找时找不到google-services.json   不推荐使用registerResGeneratingTask,请使用registerGeneratedResFolders(FileCollection)   在[src / nullnull / release,src / release / nullnull,src / nullnull,src / release,src / nullnullRelease]中查找时找不到google-services.json   registerResGeneratingTask已过时,请使用registerGeneratedResFolders(FileCollection)

2 个答案:

答案 0 :(得分:1)

我猜想您必须同时添加两个软件包log4j-apilog4j-core,因为it says org.apache.logging.log4j.utilInternal utility classes for the Log4j 2 API

 dependencies {
     api "org.apache.logging.log4j:log4j-api:2.11.1"
     implementation "org.apache.logging.log4j:log4j-core:2.11.1"
}

可以像这样列出所有/特定模块的依赖项:

./gradlew :app:dependencies >> ./results/dependencies.txt

./gradlew :app:dependencies --configuration debugCompileClasspath

为了列出所有可用的配置:

./gradlew :app:dependencies | grep ' - ' | grep -v '(n)' | grep -v 'deprecated'

然后可以列出每种构建配置的依赖关系:

./gradlew :app:dependencyInsight --configuration debugCompileClasspath --dependency log4j-core

尚未尝试过,但是您是否尝试过类似的方法...

dependencies {
    annotationProcessor "org.apache.logging.log4j:log4j-core:2.11.1"
}

这是annotationProcessor迁移文档。

答案 1 :(得分:0)

最后,我必须删除所有包含org.apache.logging.log4j:log4j-core:2.10.0的库,以使其正常运行。

但是仔细看一下马丁·齐特勒的回答,因为它非常有帮助!