title: Android View Binding - Unresolved Reference in Multi Module Project
body: <h1>Issue</h1>
  <p>The <em><a href="https://github.com/AdamSHurwitz/CryptoTweets" rel="noreferrer">Crypto Tweets</a></em> sample app <code>root</code> branch implements <em><a href="https://developer.android.com/topic/libraries/view-binding" rel="noreferrer">Android View Binding</a></em> for each of the three app modules, <code>app</code>, <code>app-rx</code>, and <code>app-simple</code>. All three modules run as expected. However, in the <code>app</code> and <code>app-rx</code> module, there are Lint errors for <code>Unresolved reference</code>.</p>
  <p>For example, in the <code>app</code> and <code>app-rx</code> modules the <code>fragment_feed.xml</code> is unresolved whereas in <code>app-simple</code>, the reference shows no import error.</p>
  <p>An IssueTracker <em><a href="https://issuetracker.google.com/issues/176215130" rel="noreferrer">bug has been filed</a></em>. Please star the issue in order to raise its' awareness.</p>
  <h1>Configuration</h1>
  <ul>
  <li>Android Studio 4.1.1</li>
  <li>Build #AI-201.8743.12.41.6953283, built on November 4, 2020</li>
  <li>Runtime version: 1.8.0_242-release-1644-b3-6915495 x86_64</li>
  <li>VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o</li>
  <li>macOS 10.16</li>
  <li>GC: ParNew, ConcurrentMarkSweep</li>
  <li>Memory: 1979M</li>
  <li>Cores: 16</li>
  <li>Registry: ide.new.welcome.screen.force=true, external.system.auto.import.disabled=true</li>
  <li>Non-Bundled Plugins: com.android.tool.sizereduction.plugin, com.thoughtworks.gauge, org.jetbrains.kotlin, cn.wjdghd.unique.plugin.id, mobi.hsz.idea.gitignore, com.developerphil.adbidea, com.google.mad-scorecard</li>
  </ul>
  <h1>Architecture</h1>
  <p><em>settings.gradle</em></p>
  <pre><code>rootProject.name='CryptoTweets'
  include ':app', ':app-rx', ':app-simple'
  </code></pre>
  <p><em>Project navigation view</em></p>
  <ul>
  <li><code>app</code>: <em>CryptoTweets</em> &gt; <em>app</em> &gt; <em>src</em> &gt; <em>main</em> &gt; <em>java</em> &gt; <em>app</em> &gt; <em>cryptotweets</em> &gt; <em>feed</em> &gt; <em>FeedFragment</em></li>
  <li><code>app-rx</code>: <em>CryptoTweets</em> &gt; <em>app-rx</em> &gt; <em>src</em> &gt; <em>main</em> &gt; <em>java</em> &gt; <em>app</em> &gt; <em>cryptotweets</em> &gt; <em>feed</em> &gt; <em>FeedFragment</em></li>
  <li><code>app-simple</code>: <em>CryptoTweets</em> &gt; <em>app-simple</em> &gt; <em>src</em> &gt; <em>main</em> &gt; <em>java</em> &gt; <em>app</em> &gt; <em>cryptotweets</em> &gt; <em>feed</em> &gt; <em>FeedFragment</em></li>
  </ul>
  <h1>Implementation</h1>
  <p><em>build.gradle</em> (Project)</p>
  <pre><code>buildscript {
      ext.gradle_version = '4.1.1'
      ext.kotlin_version = '1.4.21'
      ext.kotlin_coroutines_version = '1.3.9'
      ext.appcompat = '1.2.0'
      ext.legacy_support = '1.0.0'
      ext.core_ktx = '1.3.2'
      ext.constraint_layout = '2.0.4'
      ext.navigation_version = '2.3.2'
      ext.navigation_safe_args_version = '2.3.1'
      ext.dagger_version = '2.28.1'
      ext.retrofit_version = '2.9.0'
      ext.lifecycle_livedata_ktx = '2.2.0'
      ext.room_version = '2.2.5'
      ext.room_alpha_version = '2.3.0-alpha03'
      ext.paging_version = '2.1.2'
      ext.paging_version_alpha = '3.0.0-alpha10'
      ext.coil_version = '0.13.0'
      ext.glide_version = '4.11.0'
      ext.junit = '4.13.1'
      ext.androidx_junit = '1.1.2'
      ext.espresso_core = '3.3.0'
      repositories {
          google()
          jcenter()
          
      }
      dependencies {
          classpath &quot;com.android.tools.build:gradle:$gradle_version&quot;
          classpath &quot;org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version&quot;
          classpath &quot;androidx.navigation:navigation-safe-args-gradle-plugin:$navigation_safe_args_version&quot;
      }
  }
  
  allprojects {
      repositories {
          google()
          jcenter()
          
      }
  }
  
  task clean(type: Delete) {
      delete rootProject.buildDir
  }
  </code></pre>
  <h2><code>app-simple</code></h2>
  <p>This module does not contain the View Binding Lint errors for <code>Unresolved reference</code> in the <code>FeedFragment.kt</code> for <code>FragmentFeedBinding</code>.</p>
  <p><em>build.gradle (:app-simple)</em></p>
  <pre><code>plugins {
      id 'com.android.application'
      id 'kotlin-android'
      id 'androidx.navigation.safeargs.kotlin'
      id 'kotlin-kapt'
  }
  
  android {
      compileSdkVersion 29
      buildToolsVersion &quot;29.0.3&quot;
  
      defaultConfig {
          applicationId &quot;app.cryptotweets&quot;
          minSdkVersion 21
          targetSdkVersion 29
          versionCode 1
          versionName &quot;1.0&quot;
  
          testInstrumentationRunner &quot;androidx.test.runner.AndroidJUnitRunner&quot;
      }
  
      buildTypes {
          release {
              minifyEnabled false
              proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
          }
      }
  
      compileOptions { targetCompatibility JavaVersion.VERSION_1_8 }
  
      kotlinOptions.jvmTarget = '1.8'
  
      buildFeatures.viewBinding = true
  }
  
  dependencies {
      implementation fileTree(dir: 'libs', include: ['*.jar'])
      implementation &quot;org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.4.21&quot;
      implementation 'androidx.core:core-ktx:1.3.2'
      implementation 'androidx.appcompat:appcompat:1.2.0'
      implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
  
      implementation &quot;org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.1&quot;
      implementation &quot;androidx.navigation:navigation-ui-ktx:2.3.2&quot;
      implementation &quot;androidx.navigation:navigation-fragment-ktx:2.3.2&quot;
      implementation 'androidx.legacy:legacy-support-v4:1.0.0'
      implementation &quot;com.squareup.retrofit2:retrofit:2.9.0&quot;
      implementation &quot;com.squareup.retrofit2:converter-gson:2.9.0&quot;
      implementation &quot;androidx.paging:paging-runtime-ktx:3.0.0-alpha10&quot;
      implementation &quot;io.coil-kt:coil:0.13.0&quot;
  
      testImplementation 'junit:junit:4.13.1'
      androidTestImplementation 'androidx.test.ext:junit:1.1.2'
      androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
  }
  </code></pre>
  <p><em>FeedFragment.kt</em></p>
  <pre><code>package app.cryptotweets.feed
  
  import androidx.fragment.app.Fragment
  import app.cryptotweets.R
  import app.cryptotweets.databinding.FragmentFeedBinding
  import app.cryptotweets.feed.adapter.FeedAdapter
  
  class FeedFragment : Fragment(R.layout.fragment_feed) {
  
      private val viewModel: FeedViewModel by viewModels()
      lateinit var adapter: FeedAdapter
  
      override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
          super.onViewCreated(view, savedInstanceState)
          // The View Binding reference for 'FragmentFeedBinding' imports as expected.
          val binding = FragmentFeedBinding.bind(view)
          initViewStates(binding)
      }
  }
  </code></pre>
  <h2><code>app</code></h2>
  <p>This module contains the View Binding Lint errors for <code>Unresolved reference</code> in the <code>FeedFragment.kt</code> for <code>FragmentFeedBinding</code>.</p>
  <p><em>build.gradle (:app)</em></p>
  <pre><code>plugins {
      id 'com.android.application'
      id 'kotlin-android'
      id 'androidx.navigation.safeargs.kotlin'
      id 'kotlin-kapt'
  }
  
  android {
      compileSdkVersion 29
      buildToolsVersion &quot;29.0.3&quot;
  
      defaultConfig {
          applicationId &quot;app.cryptotweets&quot;
          minSdkVersion 21
          targetSdkVersion 29
          versionCode 1
          versionName &quot;1.0&quot;
  
          testInstrumentationRunner &quot;androidx.test.runner.AndroidJUnitRunner&quot;
      }
  
      buildTypes {
          release {
              minifyEnabled false
              proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
          }
      }
  
      compileOptions { targetCompatibility JavaVersion.VERSION_1_8 }
  
      kotlinOptions.jvmTarget = '1.8'
  
      buildFeatures.viewBinding = true
  
  }
  
  dependencies {
      implementation fileTree(dir: 'libs', include: ['*.jar'])
      implementation &quot;org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version&quot;
      implementation &quot;org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_coroutines_version&quot;
      implementation &quot;androidx.appcompat:appcompat:$appcompat&quot;
      implementation &quot;androidx.legacy:legacy-support-v4:$legacy_support&quot;
      implementation &quot;androidx.core:core-ktx:$core_ktx&quot;
      implementation &quot;androidx.constraintlayout:constraintlayout:$constraint_layout&quot;
      implementation &quot;androidx.navigation:navigation-ui-ktx:$navigation_version&quot;
      implementation &quot;androidx.navigation:navigation-fragment-ktx:$navigation_version&quot;
      implementation &quot;com.google.dagger:dagger:$dagger_version&quot;
      kapt &quot;com.google.dagger:dagger-compiler:$dagger_version&quot;
      implementation &quot;com.squareup.retrofit2:retrofit:$retrofit_version&quot;
      implementation &quot;com.squareup.retrofit2:converter-gson:$retrofit_version&quot;
      implementation &quot;androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_livedata_ktx&quot;
      implementation &quot;androidx.room:room-runtime:$room_alpha_version&quot;
      implementation &quot;androidx.room:room-ktx:$room_alpha_version&quot;
      kapt &quot;androidx.room:room-compiler:$room_alpha_version&quot;
      implementation &quot;androidx.paging:paging-runtime-ktx:$paging_version_alpha&quot;
      implementation &quot;io.coil-kt:coil:$coil_version&quot;
  
      testImplementation &quot;junit:junit:$junit&quot;
      testImplementation &quot;androidx.room:room-testing:$room_version&quot;
      androidTestImplementation &quot;androidx.test.ext:junit:$androidx_junit&quot;
      androidTestImplementation &quot;androidx.test.espresso:espresso-core:$espresso_core&quot;
  }
  </code></pre>
  <p><em>FeedFragment.kt</em></p>
  <pre><code>package app.cryptotweets.feed
  
  import androidx.fragment.app.Fragment
  import app.cryptotweets.R
  import app.cryptotweets.databinding.FragmentFeedBinding
  ...
  
  class FeedFragment : Fragment(R.layout.fragment_feed) {
  
      override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
          super.onViewCreated(view, savedInstanceState)
          // Fixme: Unresolved reference for 'FragmentFeedBinding'
          val binding = FragmentFeedBinding.bind(view)
          initViewStates(binding)
      }
  }
  </code></pre>
  <h2><code>app-rx</code></h2>
  <p>This module contains the View Binding Lint errors for <code>Unresolved reference</code> in the <code>FeedFragment.kt</code> for <code>FragmentFeedBinding</code>.</p>
  <p><em>build.gradle (:app-rx)</em></p>
  <pre><code>plugins {
      id 'com.android.application'
      id 'kotlin-android'
      id 'androidx.navigation.safeargs.kotlin'
      id 'kotlin-kapt'
  }
  
  android {
      compileSdkVersion 29
      buildToolsVersion &quot;29.0.3&quot;
  
      kotlinOptions { jvmTarget = '1.8' }
  
      defaultConfig {
          applicationId &quot;app.cryptotweets&quot;
          minSdkVersion 21
          targetSdkVersion 29
          versionCode 1
          versionName &quot;1.0&quot;
  
          testInstrumentationRunner &quot;androidx.test.runner.AndroidJUnitRunner&quot;
      }
  
      buildTypes {
          release {
              minifyEnabled false
              proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
          }
      }
  
      compileOptions { targetCompatibility JavaVersion.VERSION_1_8 }
  
      buildFeatures.viewBinding = true
  
  }
  
  dependencies {
      def rx_version = '3.0.0'
      implementation fileTree(dir: 'libs', include: ['*.jar'])
      implementation &quot;org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version&quot;
      implementation &quot;androidx.appcompat:appcompat:$appcompat&quot;
      implementation &quot;androidx.legacy:legacy-support-v4:$legacy_support&quot;
      implementation &quot;androidx.core:core-ktx:$core_ktx&quot;
      implementation &quot;androidx.constraintlayout:constraintlayout:$constraint_layout&quot;
      implementation &quot;androidx.navigation:navigation-ui-ktx:$navigation_version&quot;
      implementation &quot;androidx.navigation:navigation-fragment-ktx:$navigation_version&quot;
      implementation &quot;com.google.dagger:dagger:$dagger_version&quot;
      kapt &quot;com.google.dagger:dagger-compiler:$dagger_version&quot;
      implementation &quot;com.squareup.retrofit2:retrofit:$retrofit_version&quot;
      implementation &quot;com.squareup.retrofit2:converter-gson:$retrofit_version&quot;
      implementation &quot;androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_livedata_ktx&quot;
      implementation &quot;androidx.room:room-runtime:$room_alpha_version&quot;
      implementation &quot;androidx.room:room-ktx:$room_alpha_version&quot;
      kapt &quot;androidx.room:room-compiler:$room_alpha_version&quot;
      implementation &quot;androidx.paging:paging-runtime-ktx:$paging_version&quot;
      implementation &quot;androidx.paging:paging-rxjava2-ktx:$paging_version&quot;
      implementation &quot;io.coil-kt:coil:$coil_version&quot;
      implementation &quot;io.reactivex.rxjava3:rxkotlin:$rx_version&quot;
      implementation &quot;io.reactivex.rxjava3:rxandroid:$rx_version&quot;
      implementation &quot;com.squareup.retrofit2:adapter-rxjava3:$retrofit_version&quot;
  
      testImplementation &quot;junit:junit:$junit&quot;
      testImplementation &quot;androidx.room:room-testing:$room_version&quot;
      androidTestImplementation &quot;androidx.test.ext:junit:$androidx_junit&quot;
      androidTestImplementation &quot;androidx.test.espresso:espresso-core:$espresso_core&quot;
  }
  </code></pre>
  <p><em>FeedFragment.kt</em></p>
  <pre><code>package app.cryptotweets.feed
  
  
  import androidx.fragment.app.Fragment
  import app.cryptotweets.R
  import app.cryptotweets.databinding.FragmentFeedBinding
  ...
  
  class FeedFragment : Fragment(R.layout.fragment_feed) {
  
      override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
          super.onViewCreated(view, savedInstanceState)
          // Fixme: Unresolved reference for 'FragmentFeedBinding'
          val binding = FragmentFeedBinding.bind(view)
          viewModel.launchViewEvents(this)
          initViewStates(binding)
      }
  
  }
  </code></pre>
  <h1>Attempted Solutions</h1>
  <ol>
  <li><em>File</em> &gt; <em>Sync Project with Gradle Files</em></li>
  <li><em>Build</em> &gt; <em>Clean Project</em></li>
  <li><em>Build</em> &gt; <em>Rebuild Project</em></li>
  <li><em><a href="https://developer.android.com/studio/build/build-cache#clear_the_build_cache" rel="noreferrer">Clear the build cache</a></em></li>
  <li><em>File</em> &gt; <em>Invalidate Caches / Restart…</em></li>
  <li>Update dependency library versions.</li>
  <li>Re-clone the <em><a href="https://github.com/AdamSHurwitz/CryptoTweets" rel="noreferrer">Crypto Tweets</a></em> sample app repository from GitHub.</li>
  </ol>