Reputation: 13
I have issues with view binding in android studio with inflate and root. below of inflate and root is a redline.
I also write view binding modules in build.gradle. This is my build.gradle codes.
defaultConfig {
applicationId "com.wallpaper.view"
minSdk 21
targetSdk 32
versionCode 1
versionName "1.0"
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
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
viewBinding = true
}
dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.7.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'
And this is my activity codes.
class MainActivity : AppCompatActivity() {
lateinit var binding:ActivityMainBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
}
}
I have a read line below inflate and root.
How can I fix this?
Upvotes: 0
Views: 317
Reputation: 13
I realize some of the modules in my build.gradle was not updated, Then I updated modules and issue or red line below of inflate, and root was gone. There are the codes I updated.
from this👇
android {
namespace 'com.wallpaper.view'
compileSdk 32
defaultConfig {
applicationId "com.wallpaper.view"
minSdk 21
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
To this👇
android {
namespace 'com.wallpaper.view'
compileSdk 33
defaultConfig {
applicationId "com.wallpaper.view"
minSdk 21
targetSdk 33
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
I just update the version of compileSdk and targetSdk.
Upvotes: 0