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".
-
If ur project not giving any compiled time error then ur good.Actually Binding file are static file and when u update AS then these file are recreated but in code(may be import refer to old file) that why they so error in edtior. – Hasan Khan Feb 28 '20 at 05:17
-
Found solution? – Amin Pinjari May 10 '20 at 18:35
-
@AminPinjari if you faced the same issue, then you need to update your Android Studio latest version. – Maulik Sinroja May 11 '20 at 05:10
-
@MaulikGajjar Studio version is latest one only, solved by doing regular tricks – Amin Pinjari May 11 '20 at 19:36
7 Answers
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

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

- 219
- 3
- 6
-
-
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
-
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

- 1
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:
- My application is called MyApplication. Notice that line
com.example.myapplication.databinding.ActivityMainBinding
where the application name is converted to lowercase. - The above (1) mentioned line will also be automaticaly added when you type in
private lateinit var binding: ActivityMainBinding
This resolved my issues.

- 3,778
- 1
- 12
- 34
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.

- 60,504
- 58
- 273
- 437