Reputation: 1
I have a problem with using the feature 'viewBinding' - at first look everything seems to work, however when I took a closer look on my build.gradle file I could see that in fact
buildFeatures {
viewBinding true
}
was showing this message: No candidates found for method call viewBinding. . I assume that this also causes problems in
binding.button.setOnClickListener {
val email = binding.emailEt.text.toString()
}
like unresolved references.
I tried changing some configurations in build.gradle like enabling multiDex. I also upgraded all plugins to newest versions. Cleaning the project and rebuilding it also didn't help. I have no idea what can cause this. Currently I'm using Android Studio Flamingo 2022.2.1
package com.example.testui
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.google.firebase.auth.FirebaseAuth
import com.example.testui.databinding.ActivitySignUpBinding
class SignUpActivity : AppCompatActivity() {
private lateinit var binding: ActivitySignUpBinding
private lateinit var firebaseAuth: FirebaseAuth
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivitySignUpBinding.inflate(layoutInflater)
setContentView(binding.root)
firebaseAuth = FirebaseAuth.getInstance()
binding.button.setOnClickListener {
val email = binding.emailEt.text.toString()
}
}
}
The error message is 'Unresolved reference: ActivitySignUpBinding' while rebuilding the project and 'Unresolved reference: button', 'Unresolved reference: emailEt' in .ktl file
EDIT: build.gradle content:
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'com.google.gms.google-services'
}
android {
namespace 'com.example.testui'
compileSdk 33
defaultConfig {
applicationId "com.example.testui"
minSdk 16
targetSdk 33
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildFeatures {
viewBinding true
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.10.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.8.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'com.google.firebase:firebase-auth-ktx:22.0.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
implementation 'androidx.multidex:multidex:2.0.1'
} ```
Upvotes: 0
Views: 1573