I am working one project using kotlin + Rxjava + MVVM. During development facing issue of importing view ids in Fragment or viewholder.
import kotlinx.android.synthetic.main.layout.*
unused with kotlin.
Normaly view id should used from kotlin synthetic layout imports but it directly import it from R.id that should not happen.
Kotlin plugin version : org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.40
My gradle file :
apply plugin: 'com.android.feature' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' apply plugin: 'idea' apply plugin: 'kotlin-kapt' android { compileSdkVersion 27 baseFeature true defaultConfig { minSdkVersion 23 targetSdkVersion 27 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } lintOptions { abortOnError false } } dependencies { api "com.android.support:design:$rootProject.support_library_version" api "com.android.support:appcompat-v7:$rootProject.support_library_version" api "com.android.support:recyclerview-v7:$rootProject.support_library_version" api "com.android.support:support-dynamic-animation:$rootProject.support_library_version" api "com.android.support:cardview-v7:$rootProject.support_library_version" api "com.android.support:customtabs:$rootProject.support_library_version" api "com.android.support.constraint:constraint-layout:1.1.0-beta5" api 'android.arch.lifecycle:extensions:1.1.0' api 'androidx.core:core-ktx:0.2' api "com.google.dagger:dagger:$rootProject.dagger_version" kapt "com.google.dagger:dagger-compiler:$rootProject.dagger_version" api "android.arch.persistence.room:runtime:$rootProject.room_version" kapt "android.arch.persistence.room:compiler:$rootProject.room_version" testImplementation "android.arch.persistence.room:testing:$rootProject.room_version" api "android.arch.persistence.room:rxjava2:$rootProject.room_version" androidTestImplementation "android.arch.core:core-testing:$rootProject.room_version" testImplementation "android.arch.core:core-testing:$rootProject.room_version" api "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" api "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" api 'com.jakewharton.timber:timber:4.5.1' api "com.android.support:multidex:1.0.3" api "com.github.bumptech.glide:glide:$rootProject.glide_version" api "jp.wasabeef:glide-transformations:$rootProject.glide_transformation_version" api 'com.github.bumptech.glide:okhttp3-integration:1.5.0@aar' api "io.reactivex.rxjava2:rxandroid:$rootProject.rxAndroid_version" api "io.reactivex.rxjava2:rxjava:$rootProject.rxJava_version" api "com.google.code.gson:gson:$rootProject.gson_version" api("com.squareup.retrofit2:retrofit:$rootProject.retrofit_version") { // exclude Retrofit’s OkHttp peer-dependency module and define your own module import exclude module: 'okhttp' } api "com.squareup.okhttp3:okhttp:$rootProject.okhttp_version" api "com.squareup.okhttp3:logging-interceptor:$rootProject.okhttp_version" api "com.squareup.retrofit2:adapter-rxjava2:$rootProject.retrofit_version" api "com.squareup.retrofit2:converter-gson:$rootProject.retrofit_version" api 'com.jakewharton.threetenabp:threetenabp:1.0.5' api "com.google.firebase:firebase-invites:$rootProject.play_services_version" api "com.google.firebase:firebase-core:$rootProject.play_services_version" api "com.google.firebase:firebase-config:$rootProject.play_services_version" api "com.google.firebase:firebase-perf:$rootProject.play_services_version" api "com.google.firebase:firebase-auth:$rootProject.play_services_version" api "com.google.firebase:firebase-firestore:$rootProject.play_services_version" api("com.firebaseui:firebase-ui-auth:$rootProject.firebase_ui_version") { // exclude Retrofit’s OkHttp peer-dependency module and define your own module import exclude module: 'play-services-auth' exclude module: 'firebase-auth' } // Required only if Facebook login support is required api('com.facebook.android:facebook-android-sdk:4.31.0') api "com.google.android.gms:play-services-auth:$rootProject.play_services_version" // Required only if Twitter login support is required api("com.twitter.sdk.android:twitter-core:3.0.0@aar") { transitive = true } api 'com.jakewharton.rxbinding2:rxbinding-kotlin:2.0.0' api 'com.jakewharton.rxbinding2:rxbinding-support-v4-kotlin:2.0.0' api 'com.jakewharton.rxbinding2:rxbinding-appcompat-v7-kotlin:2.0.0' api 'com.jakewharton.rxbinding2:rxbinding-design-kotlin:2.0.0' api('com.crashlytics.sdk.android:crashlytics:2.9.1@aar') { transitive = true } }
I have also tried clean build and Rebuild project.
Any idea how can i resolve this issue ?
I have tried several approaches including the solutions reported in this thread. I also found out that a lot of folks are facing this annoying problem as you can see here
Nevertheless, the most closest solution to this problem which has worked for me so far is removing apply plugin: kotlin-android-extensions
from gradle, Sync
gradle plugin and then add it again.
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