Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Package Name after implementation of data binding

I'm using Databinding with one of my project with project name com.abc.def. I've related all my views with binding like

ActivityLoginBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_login);

it worked fine but if I change my package name to com.Abc.Def it generated following error at the time of building Apk.

Cause: couldn't make a guess for com.Abc.Def.databinding.ActivityLoginBindingImpl .

Please Note:

  1. I have an old build with com.Abc.Def on playstore already live and I'm updating the version. That's why I have to Change package name.
  2. I can't remove Databinding from whole project.as it relates to all views.
  3. If I change my package name to old one ,it works fine.

I have already tried clean , rebuild and invalidate cache and restart .but no luck.

like image 759
Tejas Pandya Avatar asked Jul 10 '18 10:07

Tejas Pandya


People also ask

Can we rename the package name?

In the Pop-up dialog, click on Rename Package instead of Rename Directory. Enter the new name and hit Refactor. Click Do Refactor in the bottom. Allow a minute to let Android Studio update all changes.

Can I change Android package name?

Step 1: To rename package name in Android studio open your project in Android mode first as shown in the below image. Step 2: Now click on the setting gear icon and deselect Compact Middle Packages. Step 3: Now the packages folder is broken into parts as shown in the below image.


1 Answers

I just bumped into the same issue. I was able to fix it by toggling databinding.enabled inside Build.gradle (Module). Below is a little step-by-step guide, that I went through after renaming my company package (com.abc.myapp -> com.xyz.myapp), which got databinding to work as expected:


  1. Build > Clean Project
  2. go to your Build.gradle (Module) and disable databinding:

    android { dataBinding { enabled = false } }

  3. File > Sync Project with Gradle Files

  4. Build > Rebuild Project (no surprise: you'll get a ton of error messages)
  5. Now enable databinding again:

    android { dataBinding { enabled = true } }

  6. File > Sync Project with Gradle Files

  7. Build > Rebuild Project


Note: Some steps here may be unnecessary, but a little extra sanity checking has never done any harm during project setup, right!?

like image 123
Basti Vagabond Avatar answered Sep 19 '22 17:09

Basti Vagabond