6

Issue

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.

Configuration

  • Android Studio 4.1.1
  • Build #AI-201.8743.12.41.6953283, built on November 4, 2020
  • Runtime version: 1.8.0_242-release-1644-b3-6915495 x86_64
  • VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
  • macOS 10.16
  • GC: ParNew, ConcurrentMarkSweep
  • Memory: 1979M
  • Cores: 16
  • Registry: ide.new.welcome.screen.force=true, external.system.auto.import.disabled=true
  • 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

Architecture

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

Implementation

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-simple

This 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)
    }
}

app

This 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-rx

This 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)
    }

}

Attempted Solutions

  1. File > Sync Project with Gradle Files
  2. Build > Clean Project
  3. Build > Rebuild Project
  4. Clear the build cache
  5. File > Invalidate Caches / Restart…
  6. Update dependency library versions.
  7. Re-clone the Crypto Tweets sample app repository from GitHub.
2
  • hi, did you find solution? Commented Apr 5, 2021 at 5:45
  • 1
    I have not. Please refer to the Google bug link above that has been filed above for updates. Commented Apr 6, 2021 at 16:28

2 Answers 2

4

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

Sign up to request clarification or add additional context in comments.

Comments

0

It will surely be late, but just in case anyone else is facing the same issue, this is how I fixed it:

In my specific case, I had the next implementation in the module Gradle file:

implementation "androidx.core:core-ktx:+"

and after changing to a Kotlin specific version like this:

implementation "androidx.core:core-ktx:1.8.0"

The "Unresolved reference" build error has gone.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.