Friday 31 May 2019

Symbol$CompletionFailure: class file for ActivityDeparturesBinding not found

I have a separate Android library in a separate project for an Android app. However I link the library directly (referencing the library module directly by path or the generated AAR) I get the following error:

A problem was found with the configuration of task ':app:kaptDevelopDebugKotlin'.
> Cannot write to file '/home/m0skit0/Repos/repo/app-android/app/build/intermediates/data-binding/develop/debug/bundle-bin' specified for property 'dataBindingArtifactOutputDir' as it is a directory.

e: error: cannot access ActivityDeparturesBinding
  class file for com.blablabla.databinding.ActivityDeparturesBinding not found
  Consult the following stack trace for details.
  com.sun.tools.javac.code.Symbol$CompletionFailure: class file for com.blablabla.databinding.ActivityDeparturesBinding not found

* What went wrong:
Execution failed for task ':app:kaptDevelopDebugKotlin'.

This shows just after the task :app:transformDataBindingWithDataBindingMergeArtifactsForDevelopDebug

However the class does exist, with full canonical name. It belongs to the the library and it is correctly auto generated (without any errors) by Android's Data Binding processor on both projects. The library compiles correctly on its own. There's no further stacktrace even if the compilation is run with --stacktrace.

I have tried linking the library with compile, implementation and api, all with the same result.

Gradle version is 4.4.


UPDATE:

Updating to Gradle 5 did not solve the problem. Renaming the XML did not solve the problem.

I've also found that the error happens only when I reference the ActivityDeparturesBinding class in my code, even if the part where it is referenced is never actually called. Only importing it without referencing it does not cause the error.


UPDATE2:

This is the activity that uses the layout:

class DeparturesActivity : BaseVinPlateActivity<DeparturesViewModel, ActivityDeparturesBinding>() {

    companion object {
        fun getStartIntent(context: Context) = Intent(context, DeparturesActivity::class.java)
    }

    @Inject
    override lateinit var viewModel: DeparturesViewModel

    override val layout: Int = R.layout.activity_departures

    override fun injectThis(component: ActivityComponent) {
        component.inject(this)
    }

    override fun getToolbarTitleId(): Int = R.string.departures_title

    override fun initializeDataBindings(dataBinding: ActivityDeparturesBinding) {
        dataBinding.viewmodel = viewModel
    }
}

abstract class BaseVinPlateActivity<T: BaseVinPlateViewModel, U: ViewDataBinding> : CompoundsBaseActivity()  {

    protected abstract var viewModel: T
    protected abstract val layout: Int

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (requestCode == BARCODE_RESULT_CODE_ACTIVITY && resultCode == Activity.RESULT_OK) {
            val barcodeResult = data?.getStringExtra(BARCODE_RESULT_ACTIVITY)
            viewModel.setBarcodeResult(barcodeResult)
        }
    }

    override fun initializeView() {
        super.initializeView()
        val dataBinding = inflateDataBinding<U>(layout)
        initializeDataBindings(dataBinding)
        with (viewModel) {
            setBindValidator(Validator(dataBinding))
            loadData()
        }
    }

    protected abstract fun initializeDataBindings(dataBinding: U)
}

If I remove the initializeDataBindings() function, the error is gone. Note that commenting only the body of the function is not enough, I had to remove the whole function.

This smells like a compiler/tools bug.



from Symbol$CompletionFailure: class file for ActivityDeparturesBinding not found

No comments:

Post a Comment