Search code examples
androidkotlinandroid-viewbinding

Android ViewBinding Error: Cannot access class 'android.widget.no_name_in_PSI_3d19d79d_1ba9_4cd0_b7f5_b46aa3cd5d40'


I tried to use ViewBinding in my Android Projects, because Kotlin synthetics are deprecated. I followed the official documentation from Android Developer's site. In my build.gradle.kts I enabled ViewBinding:

android {
    ...
    buildFeatures {
            viewBinding = true
        }
}

And I tried to use it in a Fragment like:

    private var _binding: FragmentStartBinding? = null
    private val binding get() = _binding!!

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        _binding = FragmentStartBinding.inflate(inflater, container, false)
        return binding.root
    }

But binding.root shows the error: Cannot access class 'android.widget.no_name_in_PSI_3d19d79d_1ba9_4cd0_b7f5_b46aa3cd5d40'. Check your module classpath for missing or conflicting dependencies.

Android Studio Version: 4.1.2
Kotlin Version: 1.4.30
Android Gradle Plugin Version: 4.1.2
Gradle Version: 6.8.1

I already tried Clean & Rebuild, Invalidate Caches & Restart, deleting .idea and .gradle folders. Also the ViewBinding files are generated, but it's impossible to use ViewBinding.

Does anybody have a solution for this problem?

Thanks in advance for any reply.


Solution

  • The error disappeared after deleting the Copyright-Comment from the layout xml file. Then it was possible for me to use Viewbinding. I hope, it will be fixed soon, so that any kind of comments in the layout files are no problem with Viewbinding.

    So the top of my xml file looks like this:

    <?xml version="1.0" encoding="utf-8"?>
    <androidx.constraintlayout.widget.ConstraintLayout 
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/constraint_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    

    Update:
    I changed the copyright, so that the "&" is replaced with "and". That also works for me.