Kotlin - Intermittent "bad class file" error
<p>Starting today, when I attempt to build my Kotlin Android app, I am met with the following error in my Gradle build:</p>

<pre><code>Error:cannot access Baz
bad class file: /Users/me/projects/site/android/app/build/tmp/kapt/debug/classFileStubs/com/company/foo/Bar$Baz.class
bad RuntimeInvisibleParameterAnnotations attribute: Baz(FragmentManager)
Please remove or make sure it appears in the correct subdirectory of the classpath.
</code></pre>

<p>It is pointing to an inner class Baz which extends android.support.v4.app.FragmentStatePagerAdapter. I am able to temporarily get around the error by commenting out the class, and any references to it in the outer class, and rebuilding. The error goes away, but obviously the class no longer exists so other things break at runtime. Then, if I uncomment it and build, it will work for a few builds. Then the error comes back. Rinse and repeat. I think closing the Genymotion emulator may trigger it.</p>

<p>Anyone else run into this, or have any ideas?</p>

<p>Here is the offending code:</p>

<pre><code>class Bar : Fragment() {

    @Inject
    lateinit var api:ApiRequester
    var data : ArrayList&lt;Data&gt; = ArrayList()

    override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        //[...] view creation code
        //[...] data population code
        viewPager.adapter = Baz(childFragmentManager)
        //[...] more view creation code
    }

    inner class Baz(fm:FragmentManager) : FragmentStatePagerAdapter(fm) {
        override fun getCount(): Int {
            return data.count()
        }

        override fun getItem(position: Int): Fragment? {
            var jf = FooFragment()
            var bundle = Bundle()
            bundle.putParcelable("data", data[position])
            jf.arguments = bundle
            return jf
        }
    }
</code></pre>

<p>EDIT: Apologies, Baz extends FragmentStatePagerAdapter, not Fragment as I initially stated. I am using Dagger2, which could totally have an effect here.</p>