起こるエラー
Android Studioを2.2、gradleを2.2に更新した状態でProguardをかけてビルドすると、こんなエラーがたくさん出るようになってしまった。
Error: warning: Ignoring InnerClasses attribute for an anonymous inner class
(android.support.v4.app.ActivityCompat$1) 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.
こんなエラーが、数千のクラスに対して発生。
内容的としては、新しい環境でビルドをやりなおせ!ってことなんだろうけど、mavenCentralからなど、他の人が作ったライブラリーを使ってるのがほとんどなので、ビルドし直して使うのはあまりやりたくはないし、現実的ではない。
対処法
これをproguard-rules.proに追加してください。
-keepattributes EnclosingMethod
EnclosingMethodに対して、Proguardをかけないっていう設定です。
InnerClassesに手をつけないでくれるので、問題なくビルド・難読化ができるようになるというわけです。
これをつけてビルドし直すと、ごそっとエラーがなくなります。
参考リンク
What is the “Ignoring InnerClasses attribute” warning output during compilation?