【问题标题】:How to suppress "warning: Ignoring InnerClasses attribute for an anonymous inner class" with Gradle?如何使用 Gradle 抑制“警告:忽略匿名内部类的 InnerClasses 属性”?
【发布时间】:2017-02-13 09:53:41
【问题描述】:

如何使用 Gradle 抑制“警告:忽略匿名内部类的 InnerClasses 属性”?

  • 这不是重复的问题
  • 这不是在 Proguard 期间,我也不想使用 Proguard 来抑制
  • 我想禁止做正常的./gradlew assembleDebug(因为这是assertj-core - ./gradlew testDebug

依赖:

dependencies {
   testCompile "org.assertj:assertj-core:1.7.1"
}

警告:

Dex: warning: Ignoring InnerClasses attribute for an anonymous inner class
(org.assertj.core.internal.cglib.reflect.FastClassEmitter$3) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.

类似:

tasks.withType(JavaCompile) {
    sourceCompatibility = JavaVersion.VERSION_1_7
    targetCompatibility = JavaVersion.VERSION_1_7

    configure(options) {
        compilerArgs << "-Xlint:-options"    // Turn off "missing" bootclasspath warning
    }
}

我可以添加什么compilerArgs 来抑制此警告?

参考资料:

【问题讨论】:

  • 为什么不使用proguard?
  • @cipley 这发生在 assemble 上。

标签: java android gradle android-gradle-plugin javac


【解决方案1】:

不久前我尝试使用第三方库时遇到了同样的问题。该库是为 Java 1.3 编译的。我能够通过获取该库的源代码并自己构建一个 jar 文件来修复它。当然,这只有在该库的源代码可用且可以构建时才有效。

【讨论】:

  • 好的。我宁愿不编译和重新打包assertj-core。我只想让 Gradle “沉默”。
  • 偶然我偶然发现了另一个类似的问题。也许这个问题的答案会有所帮助:stackoverflow.com/a/40173052/5956451
  • 我使用assertj-core 进行单元测试。这不会编译到应用程序中,因此我不会针对它运行 proguard。
【解决方案2】:

@SuppressWarnings("unchecked") 替换未选中的没有帮助吗? 更多示例在这里: http://www.codejava.net/java-core/the-java-language/suppresswarnings-annotation-examples

【讨论】:

  • 这不是未经检查的异常。
猜你喜欢
  • 2018-03-18
  • 2017-02-12
  • 2018-06-25
  • 2016-07-29
  • 2015-01-15
  • 2013-06-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多