Home > Enterprise >  View binding In different Activity but same project
View binding In different Activity but same project

Time:02-24

enter image description here

I have different activities in the same project and in the main activity I have done view binding as well and it worked fine but in a different activity "RegisterActivity" when i want to do view binding I am facing this error. Please help. I have done the necessary changes in the build.gradle files earlier when i did view binding in main activity.

CodePudding user response:

android { compileSdk 32

buildFeatures{
    viewBinding true
}

defaultConfig {
    applicationId "com.example.cpapp"
    minSdk 23
    targetSdk 32
    versionCode 1
    versionName "1.0"

    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles
        getDefaultProguardFile('proguardandroidoptimize.txt'),'proguard- 
        rules.pro'
    }
}

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
    jvmTarget = '1.8'
}

}

dependencies {

implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation 'com.android.databinding:viewbinding:7.1.1'
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation 'com.google.code.gson:gson:2.9.0'
implementation 'com.squareup.okhttp3:logging-interceptor:5.0.0-alpha.4'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.9.0'
implementation 'io.reactivex.rxjava2:rxjava:2.2.21'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
implementation 'com.google.android.gms:play-services-auth:19.0.0'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.0-nativemt'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0-native-mt'

}

CodePudding user response:

In Android ViewBindings are introduced at this moment of this talk at Google IO/19. It will be available with Android Studio 3.6 and as you mentioned, you're using Android Studio 3.4.2 so it's not working. Read the ViewBindings portion in this article for more references. Hope this helps!

android {
...
buildFeatures {
    viewBinding true
}

}

For more detail read official docs

  • Related