インナークラスが原因でProGuardからエラーが発生する場合の対処法について

OpenCSVを組み込んだところ、コンパイルは通るものの以下のようなエラーが発生するようになった。
使用しているAndroid Studioのバージョンは、2.2.3です。

目次

原因

インナークラスのorg.apache.commons.collectionsの中で何かが起きているようで、再コンパイルを求められているようです。
そんなことは難しいので、これに反応しているProGuardを無効してしまいましょう。

Information:Gradle tasks [:app:clean, :app:generateDebugSources, :app:mockableAndroidJar, :app:prepareDebugUnitTestDependencies, :app:generateDebugAndroidTestSources, :app:assembleDebug]
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:(org.apache.commons.collections.BeanMap$7) 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:(org.apache.commons.collections.BeanMap$8) 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:(org.apache.commons.collections.BeanMap$9) 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:(org.apache.commons.collections.BinaryHeap$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:(org.apache.commons.collections.BeanMap$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:(org.apache.commons.collections.BeanMap$10) 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:(org.apache.commons.collections.BeanMap$11) 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:(org.apache.commons.collections.BeanMap$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:(org.apache.commons.collections.BeanMap$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.
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:(org.apache.commons.collections.BeanMap$4) 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:(org.apache.commons.collections.BeanMap$5) 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:(org.apache.commons.collections.BeanMap$6) 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:(org.apache.commons.collections.BoundedFifoBuffer$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:(org.apache.commons.collections.DoubleOrderedMap$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:(org.apache.commons.collections.DoubleOrderedMap$1$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:(org.apache.commons.collections.DoubleOrderedMap$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:(org.apache.commons.collections.DoubleOrderedMap$2$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:(org.apache.commons.collections.DoubleOrderedMap$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.
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:(org.apache.commons.collections.DoubleOrderedMap$3$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:(org.apache.commons.collections.DoubleOrderedMap$4) 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:(org.apache.commons.collections.DoubleOrderedMap$4$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:(org.apache.commons.collections.DoubleOrderedMap$5) 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:(org.apache.commons.collections.DoubleOrderedMap$5$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:(org.apache.commons.collections.DoubleOrderedMap$6) 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:(org.apache.commons.collections.DoubleOrderedMap$6$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:(org.apache.commons.collections.ReferenceMap$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:(org.apache.commons.collections.ReferenceMap$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:(org.apache.commons.collections.ReferenceMap$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.
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:(org.apache.commons.collections.SequencedHashMap$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:(org.apache.commons.collections.SequencedHashMap$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:(org.apache.commons.collections.SequencedHashMap$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.
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:(org.apache.commons.collections.UnboundedFifoBuffer$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:(org.apache.commons.collections.buffer.BoundedFifoBuffer$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:(org.apache.commons.collections.buffer.PriorityBuffer$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:(org.apache.commons.collections.buffer.UnboundedFifoBuffer$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:(org.apache.commons.collections.map.ListOrderedMap$ValuesView$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:(org.apache.commons.collections.map.ListOrderedMap$KeySetView$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.
Information:BUILD SUCCESSFUL
Information:Total time: 27.639 secs
Information:296 errors
Information:0 warnings
Information:See complete output in console

appのbuild.gradle内にあるbuildTypesのdebugとreleaseのminifyEnabledをtrueに変更します。

build.gradle
buildTypes {
    debug
    {
        minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
    release
    {
        minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

これで、proguard-rules.proに記述したProGuardの設定が有効になります。

次にproguard-rules.proへインナークラスに関するエラーが発生しないように設定します。

proguard-rules.pro
-keepattributes InnerClasses

コンパイルし直して、エラーが発生しないか確認します。
OpenCSVの場合、これだけでは収まりませんでした。

発生している箇所をProGuardに追加設定します。

proguard-rules.pro
-dontwarn com.opencsv.bean.*
-dontwarn org.apache.commons.*
-dontwarn org.apache.commons.beanutils.*
-dontwarn org.apache.commons.collections.*
-dontwarn org.apache.commons.beanutils.locale.*

私の環境では、これでエラーが発生しなくなりました。

以上、インナークラスが原因でProGuardからエラーが発生する場合の対処法についてでした。