【问题标题】:Getting "EnclosingMethod" errors on building in Android Studio 2在 Android Studio 2 中构建时出现“EnclosureMethod”错误
【发布时间】:2016-08-14 06:07:41
【问题描述】:

当我在 Android Studio 2 中运行应用程序时,我遇到了构建错误。当我使用早期版本的 Android Studio 时,这些错误不存在。

Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:(com.squareup.haha.guava.base.Joiner$1) that doesn't come with an
Error:associated EnclosingMethod attribute. This class was probably produced by a
Error:compiler that did not target the modern .class file format. The recommended
Error:solution is to recompile the class from source, using an up-to-date compiler
Error:and without specifying any "-target" type options. The consequence of ignoring
Error:this warning is that reflective operations on this class will incorrectly
Error:indicate that it is *not* an inner class.
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:(com.squareup.haha.guava.collect.Iterables$2) that doesn't come with an
Error:associated EnclosingMethod attribute. This class was probably produced by a
Error:compiler that did not target the modern .class file format. The recommended
Error:solution is to recompile the class from source, using an up-to-date compiler
Error:and without specifying any "-target" type options. The consequence of ignoring
Error:this warning is that reflective operations on this class will incorrectly
Error:indicate that it is *not* an inner class.
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:(com.squareup.haha.guava.collect.Iterables$3) that doesn't come with an
Error:associated EnclosingMethod attribute. This class was probably produced by a
Error:compiler that did not target the modern .class file format. The recommended
Error:solution is to recompile the class from source, using an up-to-date compiler
Error:and without specifying any "-target" type options. The consequence of ignoring
Error:this warning is that reflective operations on this class will incorrectly
Error:indicate that it is *not* an inner class.

这些错误是什么以及如何解决?此外,apk 构建良好,应用程序也运行良好。

【问题讨论】:

标签: android android-studio-2.0


【解决方案1】:

2016/09/19 更新

这在 LeakCanary 1.4 中已修复,因此只需升级即可修复它,而无需与 haha 的替代版本混淆。

debugCompile 'com.squareup.leakcanary:leakcanary-android:1.4'

以前

这些警告是由haha:2.0.2 引起的,它是leakcanary-android:1.4-beta2 的依赖项。

它已在 haha:2.0.3 中修复,因此您可以通过在依赖项中显式使用较新版本来修复它。为每个要添加 leakcanary 依赖项的风味添加此行。你不需要为leakcanary-android-no-op 添加它,因为它没有依赖关系。

debugCompile 'com.squareup.haha:haha:2.0.3'

【讨论】:

  • 这是摆脱这个恼人警告的最简单方法。谢谢
【解决方案2】:

添加

-keepattributes EnclosingMethod

到 proguard 的配置文件(在我的例子中,proguard.cfg)似乎已经解决了这个问题。

【讨论】:

  • 调试版本通常不使用 proguard 构建(因为它需要很长时间,所以大多数配置都没有它).. 但我想它应该......
【解决方案3】:

我遇到了同样的错误。似乎leakcanary(在我的情况下)存在一些问题。我尝试在 proguard 文件中进行更改。

-dontwarn com.squareup.haha.guava.**
-dontwarn com.squareup.haha.perflib.**
-dontwarn com.squareup.haha.trove.**
-dontwarn com.squareup.leakcanary.**
-keep class com.squareup.haha.** { *; }
-keep class com.squareup.leakcanary.** { *; }

# Marshmallow removed Notification.setLatestEventInfo()
-dontwarn android.app.Notification

我不再遇到这些问题了。这是link

【讨论】:

    【解决方案4】:

    我通过向我的 build.gradle 添加以下依赖项解决了这个问题:

    testCompile "com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta2"

    这里是链接:https://github.com/square/leakcanary/issues/491

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-14
      • 2018-09-28
      • 1970-01-01
      • 1970-01-01
      • 2023-02-13
      • 2015-12-09
      • 2019-03-30
      • 2020-08-23
      相关资源
      最近更新 更多