5

I had updated an Android Studio 3.6 and then it shows me an error "Unresolved reference: ActivityMainBinding". But I have wondered that the project still working the same as the previous android studio version. Just only gave me an error "Unresolved reference: ActivityMainBinding".

Maulik Sinroja
  • 191
  • 1
  • 6
  • 17

7 Answers7

4

DataBinding class will be generated based on your XML file name.

If your xml name is activity_main.xml then the DataBinding class name will be ActivityMainBinding.

If your xml name is main_activity.xml then the DataBinding class name will be MainActivityBinding.

Don't forget to clean and build the project once

~

I also had this problem and the solution was shared from https://stackoverflow.com/a/35883531/7952086

jeanluc rotolo
  • 165
  • 1
  • 11
1

What finally worked for me:

  • clean
  • invalidate/restart caches
  • rebuild
Quentin vk
  • 313
  • 3
  • 9
0

Build -> Clean Project

Build -> Rebuild Project

Hope this will help. Thanks

Haseeb Mirza
  • 432
  • 2
  • 7
0

Me also caused same problem, but resolves with adding "kapt" plugins. Try to apply kapt plugins.

AnonyKnow
  • 219
  • 3
  • 6
  • or changes kotlin-stdlib-jdk's dependencies 7 -> 8 – AnonyKnow Mar 03 '20 at 06:19
  • On my project, I just upgraded the Android Studio 3.5 to 3.6 with all its dependencies. I also changed the dependencies 7 to 8, but still the same problem. But I still wondering that when I compile the project and run it on the device, it couldn't give me an error, and it works fine. I have created the same android code into the new project with some simple code and that couldn't give any issue with data binding in Android Studio 3.6. I have done all the possibilities, but couldn't fix the issue. – Maulik Sinroja Mar 03 '20 at 06:59
  • Check https://issuetracker.google.com/issues/149630915, hopefully the next patch may fix this issue. – AnonyKnow Mar 04 '20 at 04:33
  • Thanks for helping me here. But I have done the R&D when I am adding the custom layout files like as below `android { defaultConfig { sourceSets { main.res.srcDirs = [ 'src/main/res/splash' ] } } }` Then it will not generate the binding class file at all. But when I am cut that file and paste into the regular layout folder then it will be generated automatically and then again I move that file normal layout folder to custom layout folder then it will work normally. – Maulik Sinroja Mar 04 '20 at 06:43
  • for your helping, its resolved in the new patch of the android studio version. – Maulik Sinroja Apr 06 '20 at 06:19
  • I faced same today in 3.6.3 – Amin Pinjari May 10 '20 at 18:36
0

you must make sure that : 1-your connexion internet is on"in manifest "( ) 2-in build gradle add in android{

    buildTypes {
    release {
    minifyEnabled false
    proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard- 
    rules.pro'
    }
}

dataBinding {
    enabled = true
}     
                             }

3-sync now then ctrl+espace to the ActivityMainBinding

sarra
  • 1
0

As of 5.5.2021:

App build.gradle:

buildFeatures{
    viewBinding = true
}

MainActivity.kt:

..
import com.example.myapplication.databinding.ActivityMainBinding

class MainActivity : AppCompatActivity() {
    private lateinit var binding: ActivityMainBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        val binding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(binding.root)
    }
}
..

activity_main.xml:

For simple view bindings (as opposed to data binding) you can leave the outer tag to default:<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" ..>

No <layout> tag required!


Things to note:

  1. My application is called MyApplication. Notice that line com.example.myapplication.databinding.ActivityMainBinding where the application name is converted to lowercase.
  2. The above (1) mentioned line will also be automaticaly added when you type in private lateinit var binding: ActivityMainBinding

This resolved my issues.

glades
  • 3,778
  • 1
  • 12
  • 34
-1

Its nothing. You just need to do "Invalidate cache and restart" once.

It happens when some times the binding file is cleared when we clean the project. It will be created automatically.

Thank you.

Pratik Butani
  • 60,504
  • 58
  • 273
  • 437