The Crypto Tweets sample app root branch implements Android View Binding for each of the three app modules, app, app-rx, and app-simple. All three modules run as expected. However, in the app and app-rx module, there are Lint errors for Unresolved reference.
For example, in the app and app-rx modules the fragment_feed.xml is unresolved whereas in app-simple, the reference shows no import error.
An IssueTracker bug has been filed. Please star the issue in order to raise its' awareness.
settings.gradle
rootProject.name='CryptoTweets'
include ':app', ':app-rx', ':app-simple'
Project navigation view
app: CryptoTweets > app > src > main > java > app > cryptotweets > feed > FeedFragment
app-rx: CryptoTweets > app-rx > src > main > java > app > cryptotweets > feed > FeedFragment
app-simple: CryptoTweets > app-simple > src > main > java > app > cryptotweets > feed > FeedFragment
build.gradle (Project)
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 "com.android.tools.build:gradle:$gradle_version"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$navigation_safe_args_version"
    }
}
allprojects {
    repositories {
        google()
        jcenter()
        
    }
}
task clean(type: Delete) {
    delete rootProject.buildDir
}
app-simpleThis module does not contain the View Binding Lint errors for Unresolved reference in the FeedFragment.kt for FragmentFeedBinding.
build.gradle (:app-simple)
plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'androidx.navigation.safeargs.kotlin'
    id 'kotlin-kapt'
}
android {
    compileSdkVersion 29
    buildToolsVersion "29.0.3"
    defaultConfig {
        applicationId "app.cryptotweets"
        minSdkVersion 21
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    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 "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.4.21"
    implementation 'androidx.core:core-ktx:1.3.2'
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.1"
    implementation "androidx.navigation:navigation-ui-ktx:2.3.2"
    implementation "androidx.navigation:navigation-fragment-ktx:2.3.2"
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation "com.squareup.retrofit2:retrofit:2.9.0"
    implementation "com.squareup.retrofit2:converter-gson:2.9.0"
    implementation "androidx.paging:paging-runtime-ktx:3.0.0-alpha10"
    implementation "io.coil-kt:coil:0.13.0"
    testImplementation 'junit:junit:4.13.1'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
FeedFragment.kt
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)
    }
}
appThis module contains the View Binding Lint errors for Unresolved reference in the FeedFragment.kt for FragmentFeedBinding.
build.gradle (:app)
plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'androidx.navigation.safeargs.kotlin'
    id 'kotlin-kapt'
}
android {
    compileSdkVersion 29
    buildToolsVersion "29.0.3"
    defaultConfig {
        applicationId "app.cryptotweets"
        minSdkVersion 21
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    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 "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_coroutines_version"
    implementation "androidx.appcompat:appcompat:$appcompat"
    implementation "androidx.legacy:legacy-support-v4:$legacy_support"
    implementation "androidx.core:core-ktx:$core_ktx"
    implementation "androidx.constraintlayout:constraintlayout:$constraint_layout"
    implementation "androidx.navigation:navigation-ui-ktx:$navigation_version"
    implementation "androidx.navigation:navigation-fragment-ktx:$navigation_version"
    implementation "com.google.dagger:dagger:$dagger_version"
    kapt "com.google.dagger:dagger-compiler:$dagger_version"
    implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
    implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"
    implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_livedata_ktx"
    implementation "androidx.room:room-runtime:$room_alpha_version"
    implementation "androidx.room:room-ktx:$room_alpha_version"
    kapt "androidx.room:room-compiler:$room_alpha_version"
    implementation "androidx.paging:paging-runtime-ktx:$paging_version_alpha"
    implementation "io.coil-kt:coil:$coil_version"
    testImplementation "junit:junit:$junit"
    testImplementation "androidx.room:room-testing:$room_version"
    androidTestImplementation "androidx.test.ext:junit:$androidx_junit"
    androidTestImplementation "androidx.test.espresso:espresso-core:$espresso_core"
}
FeedFragment.kt
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)
    }
}
app-rxThis module contains the View Binding Lint errors for Unresolved reference in the FeedFragment.kt for FragmentFeedBinding.
build.gradle (:app-rx)
plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'androidx.navigation.safeargs.kotlin'
    id 'kotlin-kapt'
}
android {
    compileSdkVersion 29
    buildToolsVersion "29.0.3"
    kotlinOptions { jvmTarget = '1.8' }
    defaultConfig {
        applicationId "app.cryptotweets"
        minSdkVersion 21
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    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 "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation "androidx.appcompat:appcompat:$appcompat"
    implementation "androidx.legacy:legacy-support-v4:$legacy_support"
    implementation "androidx.core:core-ktx:$core_ktx"
    implementation "androidx.constraintlayout:constraintlayout:$constraint_layout"
    implementation "androidx.navigation:navigation-ui-ktx:$navigation_version"
    implementation "androidx.navigation:navigation-fragment-ktx:$navigation_version"
    implementation "com.google.dagger:dagger:$dagger_version"
    kapt "com.google.dagger:dagger-compiler:$dagger_version"
    implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
    implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"
    implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_livedata_ktx"
    implementation "androidx.room:room-runtime:$room_alpha_version"
    implementation "androidx.room:room-ktx:$room_alpha_version"
    kapt "androidx.room:room-compiler:$room_alpha_version"
    implementation "androidx.paging:paging-runtime-ktx:$paging_version"
    implementation "androidx.paging:paging-rxjava2-ktx:$paging_version"
    implementation "io.coil-kt:coil:$coil_version"
    implementation "io.reactivex.rxjava3:rxkotlin:$rx_version"
    implementation "io.reactivex.rxjava3:rxandroid:$rx_version"
    implementation "com.squareup.retrofit2:adapter-rxjava3:$retrofit_version"
    testImplementation "junit:junit:$junit"
    testImplementation "androidx.room:room-testing:$room_version"
    androidTestImplementation "androidx.test.ext:junit:$androidx_junit"
    androidTestImplementation "androidx.test.espresso:espresso-core:$espresso_core"
}
FeedFragment.kt
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)
    }
}
Had the same issue, added
implementation "androidx.compose.ui:ui-viewbinding:1.2.1"
to module Gradle file and the error on
import androidx.compose.ui.viewinterop.AndroidViewBinding disappeared
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With