Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clean project error with databinding: Unable to delete file androidx.databinding.library.baseAdapters--setter_store.json

I use Databinding. Sometimes while I make changes project may be broken. Then I go to Build -> Clean project & Re-Build project. And I get some strange error:

Unable to delete file: {path_to_project}\app\build\intermediates\data_binding_dependency_artifacts\debug\dataBindingMergeDependencyArtifactsDebug\out\androidx.databinding.library.baseAdapters--setter_store.json

Every time I don't know how to fix it, because I get this error on clean or rebuild. Even if I make Invalidate caches / Restart the problem isn't gone.

If I try to delete this file manually I get error that file is using by another process. Then I close project and successfully delete this file. But when I open the project and build it I get the same error described above.

As I can see the problem is about databinding, but I'm not sure because I saw the same problem with other files from other users on StackOverflow. Sometimes problem is gone by itself, but usually it isn't. Maybe the problem occurs because of errors in layout files, but how to find it out if there is no errors in build log.

Has anyone meet that error? Any ideas how to fix that situation without crush whole the project in undefined time range?

like image 355
LIFED Avatar asked Feb 01 '19 05:02

LIFED


People also ask

What is BR in data binding?

Note: The Data Binding Library generates a class named BR in the module package which contains the IDs of the resources used for data binding. In the example above, the library automatically generates the BR. item variable.

Is Android dataBinding deprecated?

Recently Android has announced that with Kotlin 1.4. 20, their Android Kotlin Extensions Gradle plugin will be deprecated and will no longer be shipped in the future Kotlin releases. Android Kotlin Extensions plugin brought with it two very cool features : Synthetics let you replace calls to findViewById with kotlinx.

Can not Resolve ActivityMainBinding?

I was getting the error "Can't resolve symbol ActivityMainBinding" after enabling dataBinding in build. gradle. After much trial and error, I figured out the solution was to exit / restart Android Studio. Works fine now.

What is BR class Android?

BR class is the class which is generated by the Data Binding for storing all the reactive values to handle. Observable class.


2 Answers

I have the same problem, and tried the method mentioned above. I could not find the related class in the error message when I searched in the project directory.

In the end, I suspected that it maybe ~/.gradle problem, and then recompile after deleting, and finally solved.

mv ~/.gradle ~/.gradle_bak
like image 161
hunterwong Avatar answered Sep 19 '22 15:09

hunterwong


First follow this 4 steps

  • Remove your file generated (build folder)
  • Clean your project ( simply run cmd command - > gradlew clean)
  • Invalidate cache and restart Android Studio
  • Restart computer

If not helpful please try following steps

  • Gradle sync;
  • Reinstall Java JRE & Java SDK;
  • Reinstall the latest version of Android Studio
  • Rolling back to the previous AS version
  • Invalidate cache and restart Android Studio
  • Delete the gradle and .gradle directories in the project directory;
  • Delete the .gradle directory in your directory;
  • Run gradlew clean ( simply run cmd command - > gradlew clean)
like image 33
Farid Haq Avatar answered Sep 19 '22 15:09

Farid Haq