Cannot find symbol DataBindingComponent on Android Studio 3.2 Canary 16 Kotlin project
Solution 1
Databinding libraries are being refactored as a part of androidx refactoring.
I found the databinding annotation processor dependency link from google's maven repository here.
I've constructed the actual gradle dependency from there.
kapt "androidx.databinding:databinding-compiler:3.2.0-alpha16"
Update As of Android studio 3.2.0-beta01, databinding no longer needs its annotation processor dependency to be declared in the gradle file, since databinding is capable of resolving its dependency.
Solution 2
With the following setup
Android Studio 3.2.1 Build #AI-181.5540.7.32.5056338, built on October 8, 2018 JRE: 1.8.0_152-release-1136-b06 x86_64 JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o macOS 10.13.3
And DataBinding simply enable by having this in my app build.gradle
apply plugin: 'kotlin-kapt'
and then
dataBinding {
enabled = true
}
and also this in my gradle.wrapper properties
android.databinding.enableV2=true
I had the same errors:
could not find the DataBindingComponent class.
I had more than 100 of them. It turned out that those errors were not important and that the true underlying error was not showed by the IDE. Therefore, I increased the number of errors that the Kotlin compiler can display by adding this in build.gradle:
dataBinding {
enabled = true
}
kapt {
javacOptions {
// Increase the max count of errors from annotation processors.
// Default is 100.
option("-Xmaxerrs", 500)
}
}
An suddenly, right below all those fake errrors, I saw the real one caused by a failed merge conflict resolution 😔
Solution 3
Just delete the compiler dependency (kapt "com.android.databinding:compiler:$gradleVersion), that worked for me. Apparently, it is provided with binding plugin from 3.2.0.
Solution 4
Same Error here on Android Studio 3.3.1, no Kotlin, pure Java, using androidx
build.gradle contains
dataBinding {
enabled true
}
gradle.properties contains
android.useAndroidX=true
android.enableJetifier=true
android.databinding.enableV2=true
I've been fighting the issue for hours and then solved it as follows:
Temporarily declare an empty interface for DataBindingComponent in your Project (in src/main/java/androidx.databinding/DataBindingComponent.java
)
package androidx.databinding;
public interface DataBindingComponent {
}
Let it compile and the error will be gone. But now the actual root error will be revealed. The one that was actually causing all the trouble but was somehow swallowed. In my case it was coming from AutoValue indicating that i was using it incorrectly
error: Parameter type java.lang.Boolean of setter method should be boolean to match getter
fixing that and then removing the dummy interface makes the compiler happy again.
Solution 5
If You're already using Android Studio 3.2 stable version, Just remove the dependency, it's already included.
Related videos on Youtube
juliano.net
Updated on July 20, 2021Comments
-
juliano.net almost 3 years
I just created a new project on Android Studio 3.2 Canary 16 with Kotlin enabled. Then I also enabled data binding, but I'm getting an error saying that it could not find the DataBindingComponent class.
Here's my project gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { ext.kotlin_version = '1.2.41' ext.android_plugin_version = '3.2.0-alpha10' repositories { google() jcenter() } dependencies { classpath 'com.android.tools.build:gradle:3.2.0-alpha16' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { google() jcenter() } } task clean(type: Delete) { delete rootProject.buildDir }
My module gradle file:
apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-kapt' apply plugin: 'kotlin-android-extensions' android { compileSdkVersion 27 defaultConfig { applicationId "net.julianonunes.myapp" minSdkVersion 22 targetSdkVersion 27 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } dataBinding { enabled = true } } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation"org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" implementation 'com.android.support:appcompat-v7:27.1.1' implementation 'com.android.support.constraint:constraint-layout:1.1.0' implementation 'com.squareup.okhttp3:okhttp:3.10.0' implementation 'com.android.support:design:27.1.1' kapt "com.android.databinding:compiler:3.1.2" }
My activity's xml:
<?xml version="1.0" encoding="utf-8"?> <layout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools"> <data> <variable name="data" type="net.julianonunes.myapp.RegisterData" /> </data> .... </layout>
And here's the build output:
Executing tasks: [clean, :app:assembleDebug] Configuration on demand is an incubating feature. > Configure project :app app: 'annotationProcessor' dependencies won't be recognized as kapt annotation processors. Please change the configuration name to 'kapt' for these artifacts: 'androidx.databinding:databinding-compiler:3.2.0-alpha16'. > Task :clean > Task :app:clean > Task :app:preBuild UP-TO-DATE > Task :app:preDebugBuild > Task :app:compileDebugAidl NO-SOURCE > Task :app:compileDebugRenderscript > Task :app:checkDebugManifest > Task :app:generateDebugBuildConfig > Task :app:prepareLintJar UP-TO-DATE > Task :app:mainApkListPersistenceDebug > Task :app:generateDebugResValues > Task :app:generateDebugResources > Task :app:mergeDebugResources > Task :app:createDebugCompatibleScreenManifests > Task :app:processDebugManifest > Task :app:splitsDiscoveryTaskDebug > Task :app:processDebugResources > Task :app:generateDebugSources > Task :app:dataBindingExportBuildInfoDebug > Task :app:transformDataBindingBaseClassLogWithDataBindingMergeGenClassesForDebug > Task :app:transformDataBindingWithDataBindingMergeArtifactsForDebug > Task :app:dataBindingGenBaseClassesDebug Download https://dl.google.com/dl/android/maven2/com/android/databinding/compiler/3.1.2/compiler-3.1.2.pom Download https://dl.google.com/dl/android/maven2/com/android/databinding/compiler/3.1.2/compiler-3.1.2.jar > Task :app:kaptGenerateStubsDebugKotlin e: /home/juliano/Documents/Projetos/myapp/app/build/generated/data_binding_base_class_source_out/debug/dataBindingGenBaseClassesDebug/out/net/julianonunes/myapp/databinding/ActivityMainBinding.java:28: error: cannot find symbol protected ActivityMainBinding(DataBindingComponent _bindingComponent, View _root, ^ symbol: class DataBindingComponent location: class ActivityMainBinding e: /home/juliano/Documents/Projetos/myapp/app/build/generated/data_binding_base_class_source_out/debug/dataBindingGenBaseClassesDebug/out/net/julianonunes/myapp/databinding/ActivityMainBinding.java:46: error: cannot find symbol @Nullable ViewGroup root, boolean attachToRoot, @Nullable DataBindingComponent component) { ^ symbol: class DataBindingComponent location: class ActivityMainBinding e: /home/juliano/Documents/Projetos/myapp/app/build/generated/data_binding_base_class_source_out/debug/dataBindingGenBaseClassesDebug/out/net/julianonunes/myapp/databinding/ActivityMainBinding.java:57: error: cannot find symbol @Nullable DataBindingComponent component) { ^ symbol: class DataBindingComponent location: class ActivityMainBinding e: /home/juliano/Documents/Projetos/myapp/app/build/generated/data_binding_base_class_source_out/debug/dataBindingGenBaseClassesDebug/out/net/julianonunes/myapp/databinding/ActivityMainBinding.java:68: error: cannot find symbol @Nullable DataBindingComponent component) { ^ symbol: class DataBindingComponent location: class ActivityMainBinding e: [kapt] An exception occurred: java.lang.NullPointerException at java.io.File.<init>(File.java:277) at android.databinding.annotationprocessor.ProcessExpressions.onHandleStep(ProcessExpressions.java:77) at android.databinding.annotationprocessor.ProcessDataBinding$ProcessingStep.runStep(ProcessDataBinding.java:203) at android.databinding.annotationprocessor.ProcessDataBinding$ProcessingStep.access$000(ProcessDataBinding.java:188) at android.databinding.annotationprocessor.ProcessDataBinding.doProcess(ProcessDataBinding.java:90) at android.databinding.annotationprocessor.ProcessDataBinding.process(ProcessDataBinding.java:65) at org.jetbrains.kotlin.kapt3.ProcessorWrapper.process(annotationProcessing.kt:131) at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:794) at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:705) at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$1800(JavacProcessingEnvironment.java:91) at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1035) at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1176) at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1170) at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1068) at org.jetbrains.kotlin.kapt3.AnnotationProcessingKt.doAnnotationProcessing(annotationProcessing.kt:87) at org.jetbrains.kotlin.kapt3.AnnotationProcessingKt.doAnnotationProcessing$default(annotationProcessing.kt:45) at org.jetbrains.kotlin.kapt3.AbstractKapt3Extension.runAnnotationProcessing(Kapt3Extension.kt:257) at org.jetbrains.kotlin.kapt3.AbstractKapt3Extension.analysisCompleted(Kapt3Extension.kt:212) at org.jetbrains.kotlin.kapt3.ClasspathBasedKapt3Extension.analysisCompleted(Kapt3Extension.kt:95) at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM$analyzeFilesWithJavaIntegration$2.invoke(TopDownAnalyzerFacadeForJVM.kt:97) at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(TopDownAnalyzerFacadeForJVM.kt:107) at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration$default(TopDownAnalyzerFacadeForJVM.kt:84) at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:374) at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:64) at org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport.analyzeAndReport(AnalyzerWithCompilerReport.kt:101) at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyze(KotlinToJVMBytecodeCompiler.kt:365) at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:130) at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:161) at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:63) at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:107) at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:51) at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:96) at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$1$1$2.invoke(CompileServiceImpl.kt:405) at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$1$1$2.invoke(CompileServiceImpl.kt:98) at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:920) at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:98) at org.jetbrains.kotlin.daemon.common.DummyProfiler.withMeasure(PerfUtils.kt:137) at org.jetbrains.kotlin.daemon.CompileServiceImpl.checkedCompile(CompileServiceImpl.kt:950) at org.jetbrains.kotlin.daemon.CompileServiceImpl.doCompile(CompileServiceImpl.kt:919) at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:404) at sun.reflect.GeneratedMethodAccessor91.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:346) at sun.rmi.transport.Transport$1.run(Transport.java:200) at sun.rmi.transport.Transport$1.run(Transport.java:197) at java.security.AccessController.doPrivileged(Native Method) at sun.rmi.transport.Transport.serviceCall(Transport.java:196) at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683) at java.security.AccessController.doPrivileged(Native Method) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) > Task :app:kaptDebugKotlin FAILED FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':app:kaptDebugKotlin'. > Compilation error. See log for more details * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. * Get more help at https://help.gradle.org Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0. See https://docs.gradle.org/4.7/userguide/command_line_interface.html#sec:command_line_warnings BUILD FAILED in 8s 20 actionable tasks: 19 executed, 1 up-to-date
What is wrong with my project?
PS: The problem also happens on Android Studio 3.1.2
-
Mygod almost 6 yearsFor me the true error was actually printed after this. After fixing that error, this one goes away as well.
-
androidguy over 5 yearsIn my case no other error was shown in log, but after reviewing my diffs I found an unimported annotation in some kt file. After fixing import, build works. Seems to be some problem in kapt processor.
-
Chetan Chaudhari over 5 yearsCannot find symbol DataBindingComponent when build from command line using ./gradlew assembleDebug
-
MMK over 5 years
android.databinding.enableV2=false android.enableExperimentalFeatureDatabinding = false
. adding this tograde.properties
solved my problem
-
-
juliano.net about 6 yearsI'm already using Canary 16 and Gradle 4.7, but it is not working.
-
Amir Uval almost 6 yearsDidn't work for me. What does the above do? Where did you find it?
-
Edijae Crusar almost 6 years@auval
android.useAndroidX:
When set totrue
, this flag indicates that you want to start using AndroidX from now on. If the flag is absent, Android Studio behaves as if the flag were set tofalse
.android.enableJetifier:
When set totrue
, this flag indicates that you want to have tool support (from the Android Gradle plugin) to automatically convert existing third-party libraries as if they were written for AndroidX. If the flag is absent, Android Studio behaves as if the flag were set tofalse
. -
Sanjeev almost 6 yearsI'm using Android studio 3.3 Canary 11 and Gradle 4.10, and I am getting the error, so this solution dosen't do for me
-
Sanjeev almost 6 yearsDidn't work for me, I am using Android studio 3.3 these parameters are already present
-
Sanjeev almost 6 yearsI have removed this dependency and tried all below solution but nothing seems to be working
-
Samuel Robert almost 6 yearsWhat studio version are you using?
-
Sanjeev almost 6 yearsAndroid studio 3.3 Canary 11 with gradle 4.10
-
Sanjeev almost 6 yearsError : cannot find symbol DataBindingComponent, I hava data binding enable to ture in gradle, I don't know what's the problem
-
Samuel Robert almost 6 yearsEnabled DataBinding in the gradle?
-
Sanjeev almost 6 yearsI have enabled it in gradle, I have follow everything in developer.android.com/topic/libraries/data-binding/start
-
B.mansouri almost 6 yearstry to change the gradle and to remove kapt "com.android.databinding:compiler:3.1.2"
-
Sanjeev over 5 yearsI am not at all using kapt "com.android.databinding:compiler:3.1.2", but I figured out the problem, it was due to the wrong package structure and moving files from one folder to another
-
habib ullah over 5 yearsThanks you save me from disaster, at last my issue solved with your solution, i have used kapt "androidx.databinding:databinding-compiler:3.2.0" Gradle version and binding version should be same
-
SpaceMonkey over 5 yearsSolved it for me, thank you. They should have added a tooltip/autofix in the IDE.
-
cayleyh over 5 yearsDouble up for this. My error was a little different but this was the root cause. In case someone googles for it:
Caused by: java.lang.NullPointerException at java.io.File.<init>(File.java:277) at android.databinding.annotationprocessor.ProcessExpressions.onHandleStep(ProcessExpressions.java:77) at android.databinding.annotationprocessor.ProcessDataBinding$ProcessingStep.runStep(ProcessDataBinding.java:203) at android.databinding.annotationprocessor.ProcessDataBinding$ProcessingStep.access$000(ProcessDataBinding.java:188) ...
-
muetzenflo over 5 yearsI am also pretty sure that it is caused by Dagger2 in my/our case. The official documentation of DataBindingComponent even mentions dagger: "If using Dagger 2, the developer should extend this interface and annotate the extended interface as a Component." (source: developer.android.com/reference/android/databinding/…). But I don't understand exactly what to do here and if it will fix the error.
-
Dewey Reed over 5 years@muetzenflo Your info seems promising. I'll try to extend that component and see if it can fix the error.
-
Dewey Reed over 5 years@muetzenflo I've tried the solution but it didn't work. I guess it only takes effects when the app is running but the problem happens in the compile time.
-
Murat over 5 yearsworks for me, I disabled typeconverter for check and it worked
-
Tosin John over 5 yearsHi, how do I do this in a java project?
-
Ernest Zamelczyk over 5 years2.19 is out and the issue is still there
-
Dewey Reed over 5 years@ErnestZamelczyk You're right. But I found some workaround in the issuetracker. Check the updated answer if you're interested.
-
Daniel Wilson over 5 yearsThis is definitely required if you migrate to Android X and use databinding etc. I migrated on one machine but the error appeared on a different one because gradle.properties is not in source control
-
filthy_wizard over 5 yearsbunch of fake errors initially to Do with DataBindingComponent. then when i increase error size. I saw it was an issue with me using the incorrect scope with dagger.
-
Van over 5 yearsThanks! I had an issue regarding Room too. I was using
ArrayList
as a return to a query where it has to be aList
. -
Deepak Ganachari over 5 yearsThis was the only solution which worked..Thanks a lot..it helped.
-
Chetan Chaudhari over 5 yearsCannot find symbol DataBindingComponent while build from command line using ./gradlew assembleDebug
-
Krunal Shah over 5 years@habibullah for use of "androidx.databinding:databinding-compiler:3.2.0", it required to enable androidX into gradle properties. Because i tried but your solution but still getting same issue
-
Nantoka over 5 yearsJust erasing the kapt ... line in the dependency section of the gradle file solved the problem for me as well. (Android Studio 3.3)
-
m.zander over 5 yearsI spend days in my life to search errors without messages...! Thanks mate, you are the man of the year :-D
-
Eugen Pechanec over 5 yearsI had a missing import statement for an annotation value and method parameter. With Dagger 2.19 I got the databinding nonsense above. Luckily Dagger 2.21 pointed me in the right direction.
-
mochadwi over 5 yearsthanks and awesome, this fixed my issue as well (AS 3.2.1) @SamuelRobert
-
Farooq Zaman over 5 yearsThanks a lot for this answer. I have struggled a lot because of this issue.
-
Oliver Metz about 5 yearsThis solved the issue with me. Thanks! Took me 2 hours to find this and didn't scroll down far enough to see your comment. :(
-
Kannan_SJD about 5 yearsGlad this helped you! Databinding errors are hard to interpret !!
-
Alberto Garrido almost 5 yearsOMG, thank you, thank you, thank you. This worked!! thank you! I was migrating to androidx and in the final stages, after finishing, i had like 70 errors like OP. Your trick revealed 13 underlying errors. Did I say thank you? :D
-
Carson Holzheimer almost 5 yearsThis is bad. An entirely unrelated issue in room causes this issue.
-
Vitor Hugo Schwaab almost 5 yearsThis is NOT exclusive to Room. Any other annotation processor that you use can throw an exception during compilation, failing before DataBinding processor comes in play.
-
wtk over 4 yearsCan't believe this is still an issue on 1/10/2019. It should have something like [For More errors click here]. Thanks man
-
Devdroid over 4 yearsThe trick with the option("-Xmaxerrs", 500) did it. Couldn't see the correct error as it wasn't even shown. Thank you!
-
Madona wambua over 4 yearsI am stuck here too so sad.
-
krishh over 4 yearsIt is Android Studio 3.6.1 now. Still need to follow this trick to see the actual error. :(
-
ilansas about 4 yearsTHANNNNKKKKKK YOOOOOUUUUUUUU FFS
-
Reejesh PK about 4 yearsya, found the actual error in the middle, in my case, it was a query issue in room db. Thanks!
-
Reejesh PK about 4 yearsand that error remained buried in between the error stated as the question.
-
Takeshi Kaga about 4 yearsThis is great! Thank you!
-
nulldroid almost 4 yearsYou sir, saved my career in self-employment. It was like trial and error for > 8 hours. I gotta say though, I was just missing "buildFeatures.dataBinding = true" in App module. Had to set the same for all feature modules as well. May your life always be filled with honey and milk.
-
Shubham Agrawal over 3 years@zeromod Can you please add which kapt plugin? Also, what if I don't have kotlin in my project?
-
John Glen about 3 yearsI removed the dependency and it works too.
-
Mubashir Murtaza about 3 yearsid 'kotlin-kapt' i remove this line from plugins ,, and now the error disappeared.
-
Milan Sheth almost 3 yearsThanks a lot for this answer. It saved my time. Keep up the good work @Ginie
-
Shamsul over 2 yearsIt works like a charm, thank you
-
nilsi about 2 yearsThank you! It was impossible to figure this out from the error message. Nice find!