Reputation: 510
after enabling both data binding and view binding
`
buildFeatures {
viewBinding true
dataBinding true
}`
and started giving this error while running app but not while syncing gradle. Tried clean/rebuild and invalidate cache & restart, nothing is helping.Everything added correctly in gradle.
> Task :app:kaptDebugKotlin
^
symbol: class ConstraintLayout
location: class ActivityAeBinding app/build/generated/data_binding_base_class_source_out/debug/out/com/packagename/databinding/ActivityAeBinding.java:19: error: cannot find symbol
private ActivityAeBinding(@NonNull ConstraintLayout rootView) {
^
symbol: class ConstraintLayout
location: class ActivityAeBinding /app/build/generated/data_binding_base_class_source_out/debug/out/com/databinding/ActivityAeBinding.java:25: error: cannot find symbol
public ConstraintLayout getRoot() {
^
symbol: class ConstraintLayout
location: class ActivityAeBinding
> Task :app:kaptDebugKotlin FAILED
Execution failed for task ':app:kaptDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution
> java.lang.reflect.InvocationTargetException (no error message)
This is the problematic class that the compiler is complaining about while running app
// Generated by view binder compiler. Do not edit!
package com.example.databinding;
import android.support.constraint.ConstraintLayout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.viewbinding.ViewBinding;
import com.sah.android.apps.mydrawer.R;
import java.lang.NullPointerException;
import java.lang.Override;
public final class ActivityAeBinding implements ViewBinding {
@NonNull
private final ConstraintLayout rootView;
private ActivityAeBinding(@NonNull ConstraintLayout rootView) {
this.rootView = rootView;
}
@Override
@NonNull
public ConstraintLayout getRoot() {
return rootView;
}
@NonNull
public static ActivityAeBinding inflate(@NonNull LayoutInflater inflater) {
return inflate(inflater, null, false);
}
@NonNull
public static ActivityAeBinding inflate(@NonNull LayoutInflater inflater,
@Nullable ViewGroup parent, boolean attachToParent) {
View root = inflater.inflate(R.layout.activity_ae, parent, false);
if (attachToParent) {
parent.addView(root);
}
return bind(root);
}
@NonNull
public static ActivityAeBinding bind(@NonNull View rootView) {
if (rootView == null) {
throw new NullPointerException("rootView");
}
return new ActivityAeBinding((ConstraintLayout) rootView);
}
}
Upvotes: 0
Views: 1287
Reputation: 510
Answering it because want to show the emphasis of when something peculiar is wrong with your data binding or view binding it's almost certain that there is some issue in layout files.
As with my case the confusing part was the generated binding class was not part of my project idk why it was generating but after searching all my layout files I discovered one import from support library not androidx thus creating this weird issue.
Upvotes: 1
Reputation: 746
You cannot use View Binding and Data Binding at the same time.
I suggest you to remove either of them and try again.
If you still face challenge, then post complete files.
Please note that, View Binding
is intended to handle simpler use cases and the limitations of View Binding
are covered in Data Binding
. The later handles complex functionality. Please read their documentations completely for more clarity.
Also, kindly visit this page and then navigate to section Comparison with data binding
And then finally, please go through this already answered question here.
Upvotes: 0